SQL Quiz for Data Analysts: 60 MCQs on Joins, GROUP BY and Window Functions
Test the SQL that data analysts use every day: filtering, sorting, aggregates, GROUP BY and HAVING, joins, subqueries, CTEs, window functions and NULL handling. Query outputs were checked by running them.

SQL Quiz
60 questions · 7 topics · timer · instant explanations · printable mark sheet.
- Questions60 in the bank, 10–30 per attempt
- Levels20 easy · 24 medium · 16 hard
- TimeAbout 5–20 minutes
- PriceFree, no login needed
- Made byDr. Aammar Tufail, Codanics
- Updated18 November 2026
In short: the SQL Quiz is a free online multiple-choice quiz by Codanics with 60 questions on SELECT and filtering; aggregates and GROUP BY; joins; subqueries, CTEs and sets; window functions; tables, keys and DML; and NULLs and query order. You choose the number of questions and the difficulty, answer against a timer, see an explanation after every answer and finish with a printable mark sheet.
What the SQL Quiz covers
SQL is still the most requested skill in data analyst job ads. Interviewers love questions about joins, GROUP BY versus WHERE, NULLs and window functions, because small misunderstandings there produce wrong numbers in real reports.
This quiz uses standard SQL that works in MySQL, PostgreSQL, SQL Server and SQLite. Questions with a table and a query ask you to predict the result, just like a real interview.
- SELECT and filtering 9 questions
- Aggregates and GROUP BY 7 questions
- Joins 9 questions
- Subqueries, CTEs and sets 8 questions
- Window functions 10 questions
- Tables, keys and DML 8 questions
- NULLs and query order 9 questions
Who it is for: Aspiring data analysts, business intelligence learners, computer science students and anyone preparing for an SQL interview.
How the quiz works
- Type your name if you want it printed on the mark sheet (optional; it never leaves your browser).
- Choose 10, 20 or 30 questions, a difficulty (Easy, Mixed or Hard) and the timer: Standard, Relaxed or none.
- Answer each question before the timer runs out. Press A–D or 1–4 on a keyboard, or tap an option on your phone.
- Read the explanation after every answer, then press Next.
- At the end, get your score, grade, topic-wise breakdown and a full answer review. Print it or save it as a PDF.
- Retake the quiz for a fresh random set, or practise only the topics you found hard.
Free video lessons from Codanics
Score lower than you hoped? These free lessons from the Codanics YouTube channel cover the same topics, explained step by step.
Free on the Codanics YouTube channel, taught in Urdu/Hindi.
Sample questions with answers
Here are 9 questions from the bank, with answers and explanations. The quiz above draws from all 60.
1. Which clause filters individual rows before any grouping happens?
- WHERE
- HAVING
- ORDER BY
- GROUP BY
Answer: A. WHERE
WHERE filters rows before they are grouped. HAVING filters groups after GROUP BY, so it is used for conditions on aggregates.
2. Which condition is equivalent to dept IN ('HR', 'IT')?
- dept = 'HR' OR dept = 'IT'
- dept LIKE 'HR%IT'
- dept = 'HR' AND dept = 'IT'
- dept BETWEEN 'HR' AND 'IT'
Answer: A. dept = 'HR' OR dept = 'IT'
IN checks whether the value equals any item in the list, which is a chain of OR comparisons. With AND, a single value can never equal both 'HR' and 'IT'.
3. Which query lists departments that have more than 5 employees?
- SELECT dept FROM emp WHERE COUNT(*) > 5 GROUP BY dept;
- SELECT dept FROM emp GROUP BY dept HAVING COUNT(*) > 5;
- SELECT dept, COUNT(*) > 5 FROM emp;
- SELECT dept FROM emp GROUP BY dept WHERE COUNT(*) > 5;
Answer: B. SELECT dept FROM emp GROUP BY dept HAVING COUNT(*) > 5;
Conditions on aggregates go in HAVING, which is applied after grouping. Aggregates are not allowed in WHERE, because WHERE runs before groups exist.
4. What does an INNER JOIN return?
- All rows from the left table, matched or not
- Only rows that have a match in both tables
- Every combination of rows from both tables
- All rows from both tables, matched or not
Answer: B. Only rows that have a match in both tables
An INNER JOIN keeps only pairs of rows where the join condition is true. Keeping all left rows is a LEFT JOIN, and every combination is a CROSS JOIN.
5. What is a CTE (common table expression)?
- A named temporary result set defined with WITH
- A permanent table that is stored on disk
- A constraint that checks values in a column
- A special type of index that speeds up joins
Answer: A. A named temporary result set defined with WITH
A CTE is written as WITH name AS (SELECT …) and exists only for the query that follows it. It lets you name intermediate steps.
6. How does a window function such as SUM(…) OVER (…) differ from SUM with GROUP BY?
- It can be used only inside a WHERE clause
- It permanently sorts the stored table
- It keeps every input row and adds the result as a column
- It collapses each group into a single row
Answer: C. It keeps every input row and adds the result as a column
Window functions compute across a set of related rows but return one value per row, so detail rows are kept. GROUP BY returns one row per group.
7. What is a FOREIGN KEY?
- A column that is stored encrypted
- A column whose values must be unique in its own table
- The first column defined in a table
- A column whose values must match a key in another table
Answer: D. A column whose values must match a key in another table
A foreign key links tables: for example orders.customer_id must refer to an existing customers.id. This enforces referential integrity.
8. Which condition finds rows where email is missing?
- WHERE email = NULL
- WHERE email = ''
- WHERE email IS NULL
- WHERE email == NULL
Answer: C. WHERE email IS NULL
NULL means unknown, so comparing with = NULL is never true. Use IS NULL (or IS NOT NULL). An empty string is a real value, not NULL.
9. In what logical order does SQL process these clauses?
- SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY
- FROM, GROUP BY, WHERE, SELECT, HAVING, ORDER BY
- FROM, WHERE, GROUP BY, HAVING, SELECT, ORDER BY
- SELECT, WHERE, FROM, ORDER BY, GROUP BY, HAVING
Answer: C. FROM, WHERE, GROUP BY, HAVING, SELECT, ORDER BY
The query is written starting with SELECT, but it is logically evaluated from FROM. SELECT comes late, just before ORDER BY (and LIMIT).
Free guides and blogs to study
Free tools for your studies and research
Codanics also has 160+ free online tools for students and researchers: statistics calculators, meta-analysis, PDF and writing tools. They run in your browser, with no login.
Frequently asked questions
Is the SQL Quiz free?
Yes. The SQL Quiz is completely free, with no sign-up, no login and no limit on attempts.
How many questions are in the SQL Quiz?
The question bank has 60 multiple-choice questions (20 easy, 24 medium and 16 hard) across 7 topics. Each attempt draws 10, 20 or 30 of them at random, so every attempt is different.
How does the timer work?
Each question has its own countdown: about 25 seconds for easy, 40 for medium and 55 for hard questions, plus 15 seconds when there is code to read. Choose Relaxed to double the time or switch the timer off to study at your own pace. Unanswered questions count as skipped.
Can I get a certificate or mark sheet?
Yes. When you finish, you get a mark sheet with your name, score, grade, time, topic-wise performance and every answer explained. Use Print or save as PDF to keep it. It is a self-assessment result, not an official certificate.
Are the answers and explanations correct?
Every question was written and reviewed for one clearly correct answer, and code questions were checked by running the code. If you think an answer is wrong, tell us on the Codanics WhatsApp channel or in the YouTube comments and we will fix it.
Which SQL dialect does the quiz use?
Standard SQL. The queries behave the same in MySQL 8, PostgreSQL, SQL Server and SQLite. Where databases differ, the question avoids the difference.
Are window functions included?
Yes. Mixed and Hard sets include ROW_NUMBER, RANK, DENSE_RANK, LAG and running totals with OVER (PARTITION BY … ORDER BY …).
Is my data stored anywhere?
No. The quiz runs entirely in your browser. Your name, answers and score are not uploaded. Your best score and settings are remembered only in this browser so you can track your progress.
More free quizzes
See all Codanics quizzes → · Courses · Free tools · Blog



