SQL Quiz: 20 Questions for Interview Prep (2026)
SQL is the language of data, and it shows up in almost every backend, data-analyst, and data-engineering interview. The good news is that a solid grasp of a few core concepts, queries, JOINs, keys, and aggregation, covers the majority of questions you will face.
Below are 20 SQL quiz questions with clear answers and short explanations. They apply to standard SQL, so they hold true across MySQL, PostgreSQL, SQL Server, and SQLite with only minor syntax differences.
SQL Basics & Queries (1โ10)
Q1. What does SQL stand for?
โ Answer: Structured Query Language
๐ก SQL is the standard language for storing, retrieving, and managing data in a relational database.
Q2. Which statement is used to retrieve data from a table?
โ Answer: SELECT
๐ก SELECT reads data. For example, `SELECT name FROM users;` returns the name column from the users table.
Q3. Which clause filters rows based on a condition?
โ Answer: WHERE
๐ก WHERE keeps only rows that meet a condition, e.g. `WHERE age > 18`. It filters rows before any grouping.
Q4. How do you sort query results?
โ Answer: ORDER BY
๐ก ORDER BY sorts results ascending by default; add DESC for descending, e.g. `ORDER BY created_at DESC`.
Q5. Which keyword removes duplicate rows from results?
โ Answer: DISTINCT
๐ก `SELECT DISTINCT country FROM users;` returns each country only once, removing duplicates.
Q6. Which statement adds a new row to a table?
โ Answer: INSERT INTO
๐ก `INSERT INTO users (name) VALUES ('Sara');` adds a new record to the users table.
Q7. Which statement modifies existing rows?
โ Answer: UPDATE
๐ก UPDATE changes data in existing rows. Always pair it with a WHERE clause, or every row will be updated.
Q8. Which statement removes rows from a table?
โ Answer: DELETE
๐ก `DELETE FROM users WHERE id = 5;` removes matching rows. Without WHERE, it deletes all rows.
Q9. What does the LIMIT clause do?
โ Answer: Restricts the number of rows returned
๐ก `SELECT * FROM users LIMIT 10;` returns at most 10 rows. SQL Server uses TOP instead of LIMIT.
Q10. Which operator checks whether a value is within a range?
โ Answer: BETWEEN
๐ก `WHERE age BETWEEN 18 AND 30` matches values from 18 to 30 inclusive.
When writing an UPDATE or DELETE, mention that you would run the WHERE condition as a SELECT first. It shows caution and prevents accidentally changing every row.
Keys, JOINs & Aggregation (11โ20)
Q1. What is a PRIMARY KEY?
โ Answer: A column (or set of columns) that uniquely identifies each row
๐ก A primary key must be unique and cannot be NULL. Each table can have only one primary key.
Q2. What is a FOREIGN KEY?
โ Answer: A column that references the primary key of another table
๐ก Foreign keys enforce referential integrity, linking related tables (e.g. an orders table referencing a customers table).
Q3. What does an INNER JOIN return?
โ Answer: Only rows that have matching values in both tables
๐ก An INNER JOIN combines rows from two tables where the join condition is met, dropping unmatched rows.
Q4. What is the difference between INNER JOIN and LEFT JOIN?
โ Answer: LEFT JOIN returns all rows from the left table plus matches from the right (NULLs where none match)
๐ก INNER JOIN keeps only matched rows; LEFT (OUTER) JOIN keeps every left-table row even when there is no match on the right.
Q5. What does the GROUP BY clause do?
โ Answer: Groups rows that share a value so aggregate functions can be applied per group
๐ก `SELECT country, COUNT(*) FROM users GROUP BY country;` counts users per country.
Q6. What is the difference between WHERE and HAVING?
โ Answer: WHERE filters rows before grouping; HAVING filters groups after aggregation
๐ก You cannot use an aggregate like COUNT() in WHERE, but you can in HAVING, e.g. `HAVING COUNT(*) > 5`.
Q7. Name the common SQL aggregate functions.
โ Answer: COUNT, SUM, AVG, MIN, and MAX
๐ก These summarise data across rows, e.g. `AVG(salary)` returns the average salary in a group.
Q8. What is an index and why is it used?
โ Answer: A data structure that speeds up row lookups
๐ก Indexes make reads faster but slightly slow down writes and use extra storage. They are ideal on columns used in WHERE and JOIN conditions.
Q9. What is database normalization?
โ Answer: Organising tables to reduce data redundancy and improve integrity
๐ก Normalization splits data into related tables (e.g. 1NF, 2NF, 3NF) so the same information is not stored in multiple places.
Q10. What is the difference between DELETE, TRUNCATE, and DROP?
โ Answer: DELETE removes selected rows; TRUNCATE removes all rows quickly; DROP removes the entire table
๐ก DELETE can use WHERE and is logged row by row. TRUNCATE clears all rows fast with no WHERE. DROP deletes the table structure itself.
Running UPDATE or DELETE without a WHERE clause affects every row in the table. Double-check your condition before executing.
Frequently Asked Questions
Are these SQL questions good for interviews?
Yes. Queries, JOINs, keys, GROUP BY vs HAVING, indexes, and normalization are among the most commonly asked SQL topics in data-analyst, backend, and data-engineering interviews.
Do these questions apply to MySQL and PostgreSQL?
Almost entirely. They cover standard SQL, which works across MySQL, PostgreSQL, SQL Server, and SQLite. Only small syntax details differ, such as LIMIT (MySQL/PostgreSQL) versus TOP (SQL Server).
What is the best way to practise SQL?
Create a small sample database and write real queries, or use a free online SQL sandbox. Practising by actually running queries cements the concepts far better than reading alone.
๐Related Articles
Questions are checked against standard ANSI SQL behaviour and common database documentation (MySQL, PostgreSQL).