Test your basic SQL knowledge with this easy quiz covering top SQL interview questions, including queries, joins, data types, and functions. Perfect for data engineering and analytics job preparation or foundational SQL revision.
Which of the following correctly expands the abbreviation SQL?
Explanation: SQL stands for Structured Query Language, which is the correct term used for managing and querying databases. 'Standard Question Logic' and 'Sequential Query Line' are incorrect because they do not describe what SQL actually does. 'Structured Queue Language' is also a common typo but contains an inaccurate word; SQL is not about queues.
Which SQL statement selects all columns from a table named Employees?
Explanation: The correct way to select all columns from a table in SQL is 'SELECT * FROM Employees;'. 'SELECT Employees FROM *;' is not a valid syntax. 'SELECT ALL FROM Employees;' uses the wrong keyword, and 'SELECT * IN Employees;' misuses the keyword 'IN'.
Which clause is used to filter records in a SQL SELECT statement?
Explanation: 'WHERE' filters rows based on specified conditions in a SELECT statement. 'WHEN' is not a standard SQL clause for filtering. 'HAVING' is used for filtering groups after aggregation, and 'ORDER BY' is used for sorting, not filtering.
How would you get the total number of rows in a table called Orders?
Explanation: Using 'SELECT COUNT(*) FROM Orders;' will return the total number of rows in the Orders table. 'SELECT TOTAL(*) FROM Orders;' is not a valid SQL function. 'COUNT(*) Orders;' is incorrect and missing the SELECT statement. 'SELECT SUM(Orders);' attempts to add up all values, not count rows.
What is the primary purpose of a primary key in a SQL table?
Explanation: A primary key ensures each record in a table is unique, which helps maintain data integrity. It cannot be used to directly store images. While indexing on primary keys can help sorting, sorting is not its main function. Encryption is not provided by defining a primary key.
Which operator is used in SQL to search for a specified pattern in a column?
Explanation: The 'LIKE' operator is used for pattern matching in SQL, for example with the '%' wildcard. 'SIMILAR' and 'MATCH' are not standard SQL operators, and 'EQUALS' checks for exact matches, not patterns.
Which SQL clause is used to sort the result set of a query?
Explanation: 'ORDER BY' sorts the output in ascending or descending order. 'SORT BY' and 'ARRANGE BY' are often mistakenly used but are not standard SQL clauses. 'GROUP BY' is for grouping rows, not sorting them.
Which type of JOIN returns all rows from both tables, matching rows where possible?
Explanation: 'FULL OUTER JOIN' returns all rows from both joined tables, filling in NULLs where no match exists. An 'INNER JOIN' returns only matched rows. 'LEFT JOIN' and 'RIGHT JOIN' return all records from the left or right table plus matched records from the other.
Which SQL data type is most suitable for storing whole numbers?
Explanation: 'INT' is used to store whole numbers in SQL tables. 'CHAR' and 'TEXT' are for character data, while 'DATE' is for dates, not numbers. These other types cannot handle numerical operations efficiently.
Which keyword is used to return only distinct (unique) values in SQL?
Explanation: 'DISTINCT' is the correct SQL keyword for returning unique values in query results. 'UNIQUE' is related to constraints, not selecting unique rows. 'DIFFERENT' and 'VARIETY' are not valid SQL keywords.
How can you retrieve department names from a table Departments without any duplicates?
Explanation: 'SELECT DISTINCT department_name FROM Departments;' will give you department names without duplicates. 'SELECT UNIQUE' is incorrect syntax; UNIQUE is for constraints. 'SELECT department_name FROM Departments GROUP;' is incomplete and invalid. 'SELECT DIFFERENT' is not a valid SQL statement.
Which SQL function is used to replace NULL values with a specified value?
Explanation: 'COALESCE' returns the first non-NULL value in its list, which is often used to handle NULLs in SQL. 'CONCAT' combines strings, not NULL values. 'COUNT' aggregates rows, while 'CAST' changes data types.
Which SQL statement updates the salary of all employees named Mark to 5000 in the Employees table?
Explanation: The correct way to update the salary is 'UPDATE Employees SET salary=5000 WHERE name='Mark';'. 'MODIFY' and 'CHANGE' are not standard SQL keywords for updating data. 'UPDATE salary=5000 FROM Employees WHERE name='Mark';' has the wrong syntax.
Which command removes all rows from a table named Customers, but not the table itself?
Explanation: 'DELETE FROM Customers;' deletes all rows in the table but leaves the table structure intact. 'DROP TABLE Customers;' removes the entire table. 'TRUNCATE Customers;' is often used but must be written as 'TRUNCATE TABLE Customers;'. 'REMOVE Customers;' is not a valid SQL command.
Which clause in SQL is used to group records with the same values together, for example, by department?
Explanation: 'GROUP BY' allows you to arrange rows with the same values into groups, typically used for aggregation. 'ORDER BY' only sorts the results. 'SORT GROUP' and 'AS GROUP' are not valid SQL clauses for grouping data.
Which SQL function calculates the average value for a numeric column called 'age'?
Explanation: 'AVG(age)' returns the average value for the 'age' column. 'AVERAGE(age)' and 'MEAN(age)' look similar but are not valid in standard SQL. 'SUM(age)' adds up all the values, not averaging them.