STANDARD SQL · 2 TABLES · 15 QUERIES · ABOUT 12 MINUTES

Two tables. Fifteen queries. What comes back?

Every question runs against the same five employees and three departments, with a couple of NULLs left in on purpose. Each answer explains the rule, and your result is broken down by topic.

Start the SQL test
SELECT COUNT(*), COUNT(salary)
FROM employees;
countcount54
QUERY 1 / 15 · BASICSEasy

What does this return?

SELECT COUNT(*)FROM employees;
employees
idnamedept_idsalarymanager_id1Ada15000NULL2Ben1400013Cy2400014DiNULL300025Eve2NULL3
departments
idname1Eng2Sales3Legal

What this SQL test measures, in short

This test checks whether you can predict what a query returns: how NULL behaves, how joins keep or drop rows, what GROUP BY and HAVING do, and how window functions rank. It rewards understanding over memorising syntax.

Queries use standard SQL that runs the same in PostgreSQL, MySQL, SQL Server and SQLite, except where a question is about a difference between them. The questions are our own and not standardised against a population.

By What's Your IQ · Reviewed 4 Oct 2026
Format
15 predict-the-result queries, 4 options each
Topics
Basics, NULLs, joins, grouping, sorting and window functions
Data
5 employees, 3 departments; 1 missing department, 1 missing salary
Language
Developed at IBM in the 1970s; ANSI standard since 1986
WRITTEN TOP TO BOTTOM, RUN IN A DIFFERENT ORDER

SELECT happens almost last

The database logically starts with FROM and works down. That's why WHERE can't see an alias made in SELECT (question 15), and why HAVING exists at all. Step through and watch the rows change.

Numbers show the order the clauses run in.
AFTER FROM5 rows
namedept_idsalaryAda15000Ben14000Cy24000DiNULL3000Eve2NULL
Start with every row of the table.
SAME TWO TABLES, FOUR JOINS

A join is a decision about who gets left out

SELECT e.name, d.nameFROM employees eINNER JOIN departments d ON e.dept_id = d.id;
e.named.name
AdaEngBenEngCySalesEveSales
4 rows

Only rows with a match on both sides. Di (no department) and Legal (no employees) are both lost, often without anyone noticing.

50+ yearssince the relational model it's built onEdgar Codd's 1970 paper proposed storing data as tables queried by what you want, not how to fetch it. Almost every major database still works this way.1
1974SEQUEL at IBM. Donald Chamberlin and Raymond Boyce designed an English-like query language for Codd's model. A trademark clash later shortened it to SQL.2
1986Standardised. ANSI adopted SQL as a standard, followed by ISO in 1987. Every vendor still adds its own dialect, which is why question 13 has no single answer.3
2003Window functions. SQL:2003 added RANK, ROW_NUMBER and OVER, letting a query compare each row with its neighbours without collapsing them into groups.3
2024 surveyAbout half of developers. SQL was one of the most-used languages among respondents to Stack Overflow's survey, used by data analysts as much as by programmers.4
  1. Codd, E. F. (1970). A relational model of data for large shared data banks. Communications of the ACM, 13(6), 377–387.
  2. Chamberlin, D. D., & Boyce, R. F. (1974). SEQUEL: A structured English query language. Proceedings of the 1974 ACM SIGFIDET Workshop, 249–264.
  3. ISO/IEC 9075. Information technology — Database languages — SQL.
  4. Stack Overflow. (2024). 2024 Developer Survey: Technology.

Where to go next

Knowing SQL is one thing. How do you reason?

Our full IQ test measures the logic and working memory that make complex queries easier: 60 questions across four domains, about 30 minutes.

Take the full IQ test