Essential SQL Interview Questions Quiz Quiz

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.

  1. What does SQL stand for?

    Which of the following correctly expands the abbreviation SQL?

    1. Structured Queue Language
    2. Standard Question Logic
    3. Structured Query Language
    4. Sequential Query Line

    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.

  2. Selecting All Columns

    Which SQL statement selects all columns from a table named Employees?

    1. SELECT Employees FROM *;
    2. SELECT * FROM Employees;
    3. SELECT * IN Employees;
    4. SELECT ALL FROM 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'.

  3. Filtering Rows

    Which clause is used to filter records in a SQL SELECT statement?

    1. WHERE
    2. ORDER BY
    3. HAVING
    4. WHEN

    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.

  4. Counting Rows

    How would you get the total number of rows in a table called Orders?

    1. COUNT(*) Orders;
    2. SELECT COUNT(*) FROM Orders;
    3. SELECT SUM(Orders);
    4. SELECT TOTAL(*) FROM 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.

  5. Primary Key Purpose

    What is the primary purpose of a primary key in a SQL table?

    1. To store images
    2. To encrypt data
    3. To uniquely identify each record
    4. To speed up sorting

    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.

  6. String Matching Operator

    Which operator is used in SQL to search for a specified pattern in a column?

    1. SIMILAR
    2. EQUALS
    3. LIKE
    4. MATCH

    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.

  7. Ordering Results

    Which SQL clause is used to sort the result set of a query?

    1. SORT BY
    2. GROUP BY
    3. ARRANGE BY
    4. ORDER BY

    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.

  8. Combining Tables

    Which type of JOIN returns all rows from both tables, matching rows where possible?

    1. LEFT JOIN
    2. INNER JOIN
    3. FULL OUTER JOIN
    4. RIGHT JOIN

    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.

  9. Data Types in SQL

    Which SQL data type is most suitable for storing whole numbers?

    1. DATE
    2. CHAR
    3. TEXT
    4. INT

    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.

  10. Querying Unique Values

    Which keyword is used to return only distinct (unique) values in SQL?

    1. UNIQUE
    2. DISTINCT
    3. VARIETY
    4. DIFFERENT

    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.

  11. Removing Duplicate Data

    How can you retrieve department names from a table Departments without any duplicates?

    1. SELECT DIFFERENT department_name FROM Departments;
    2. SELECT UNIQUE department_name FROM Departments;
    3. SELECT DISTINCT department_name FROM Departments;
    4. SELECT department_name FROM Departments GROUP;

    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.

  12. NULL Value Handling

    Which SQL function is used to replace NULL values with a specified value?

    1. CAST
    2. CONCAT
    3. COUNT
    4. COALESCE

    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.

  13. Updating Data

    Which SQL statement updates the salary of all employees named Mark to 5000 in the Employees table?

    1. UPDATE Employees SET salary=5000 WHERE name='Mark';
    2. MODIFY Employees SET salary=5000 WHERE name='Mark';
    3. CHANGE Employees salary=5000 WHERE name='Mark';
    4. UPDATE salary=5000 FROM Employees WHERE name='Mark';

    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.

  14. Deleting Rows

    Which command removes all rows from a table named Customers, but not the table itself?

    1. REMOVE Customers;
    2. DROP TABLE Customers;
    3. TRUNCATE Customers;
    4. DELETE FROM Customers;

    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.

  15. Grouping Records

    Which clause in SQL is used to group records with the same values together, for example, by department?

    1. AS GROUP
    2. GROUP BY
    3. SORT GROUP
    4. ORDER BY

    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.

  16. Aggregation Function

    Which SQL function calculates the average value for a numeric column called 'age'?

    1. AVG(age)
    2. AVERAGE(age)
    3. MEAN(age)
    4. SUM(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.