SQL for placements: interview questions by topic
Placement rounds test SQL as a reading-and-writing skill. A screening test shows you two or three tables and asks for the query; an interviewer shows you a query and asks what it returns, then changes one word — INNER to LEFT, WHERE to HAVING, COUNT(*) to COUNT(column) — and asks again. The questions cluster: joins and the rows that survive them, aggregation and the groups it builds, subqueries and when a join does the same job, and, in product-company rounds, window functions for running totals, rankings and the second-highest salary without a self-join.
NULL is the trap that runs through all of it. It is not equal to anything, it is skipped by aggregates, and it decides what a WHERE clause does to a LEFT JOIN. Constraints, views, set operations and the string and date functions appear as one-liners that separate people who have written SQL from people who have read about it.
The pages below take one topic each: the questions interviewers ask, with clear answers and worked SQL, and one question exactly as the diagnostic asks it. The diagnostic itself draws from every SQL topic in the bank, easy to hard, and tells you which of these pages to read first.
SQL topics, one page each
10 of the 12 SQL topics in the bank have a page so far; the diagnostic draws from all 12.
- SQL JOIN interview questions
SQL JOIN questions asked in placement interviews — INNER vs LEFT vs FULL, self joins, duplicates, NULLs, ON vs WHERE — with clear answers and worked SQL.
- SQL window function interview questions
ROW_NUMBER vs RANK vs DENSE_RANK, PARTITION BY, LAG/LEAD, running totals and the frame trap — window-function interview questions with worked queries.
- SQL GROUP BY and HAVING interview questions
WHERE vs HAVING, the every-column rule, COUNT(*) vs COUNT(column), finding duplicates, counting after a LEFT JOIN, clause order — with worked SQL.
- SQL subquery interview questions
Correlated vs non-correlated, IN vs EXISTS, scalar subqueries, derived tables, ALL and ANY, subquery vs JOIN — placement questions with worked SQL.
- SQL NULL handling interview questions
Why = NULL never matches, three-valued logic, COALESCE vs IFNULL vs ISNULL, NULL in aggregates, the NOT IN trap, sorting and UNIQUE — answered.
- SQL UNION and set operations interview questions
UNION vs UNION ALL, union-compatible columns, INTERSECT and EXCEPT (MySQL support), ORDER BY with UNION, UNION vs JOIN, type coercion — worked SQL.
- SQL constraints interview questions
NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK and DEFAULT, CHECK with NULL, adding and dropping constraints, violations, deferrable — with SQL.
- SQL aggregate functions interview questions
COUNT, SUM, AVG, MIN, MAX on empty sets, DISTINCT inside aggregates, conditional aggregation and pivots, STRING_AGG, nested aggregates, integer AVG.
- SQL views interview questions
What a view is and isn't, view vs table, why views exist, updatable views, WITH CHECK OPTION, materialized views, performance, views vs CTEs vs temp tables
- SQL string and date function interview questions
LENGTH vs CHAR_LENGTH, CONCAT and NULL, SUBSTRING_INDEX, TRIM and REPLACE, year filters that keep the index, date arithmetic and age, DATE vs TIMESTAMP.
One question, exactly as the diagnostic asks it
From the SQL bank — 60 questions across 12 topics. The answer is marked because this one is public; in a sitting you choose first, then see why each option is right or wrong.
Table Departments(dept_id, dept_name). Table Employees(emp_id, name, dept_id). Which query returns all departments, including those that currently have no employees?
- 1SELECT * FROM Departments RIGHT JOIN Employees ON Departments.dept_id = Employees.dept_id;
- 2SELECT * FROM Departments LEFT JOIN Employees ON Departments.dept_id = Employees.dept_id;correct
- 3SELECT * FROM Departments INNER JOIN Employees ON Departments.dept_id = Employees.dept_id;
- 4SELECT * FROM Departments, Employees WHERE Departments.dept_id = Employees.dept_id;
A LEFT JOIN keeps every row from the left (first-listed) table even when there's no matching row on the right, filling the right-hand columns with NULL. Here Departments is listed first, so every department survives, including those with no employees. INNER JOIN and the equivalent comma-style join with a WHERE condition both drop departments without any employees, since a match is required on both sides. The RIGHT JOIN query keeps every row of the right-hand table, Employees, and only the departments that match one, so it too drops any department that has no employees -- the exact opposite of what's needed.
Measure it
Reading the answers tells you what’s true. A diagnostic tells you what you get wrong.
10 SQL questions across its topics, easy to hard, about fifteen minutes. You get a readiness figure with the arithmetic shown, the topics you missed named, and a practice set sized for today. Free: 1 diagnostic a month and 15 problems a day. No card.