SQL interview questions
The standard SQL questions for data, analyst and backend roles, with short answers and the rule behind each.
WHERE filters rows before grouping; HAVING filters groups after GROUP BY, usually on an aggregate such as COUNT or SUM.
INNER JOIN returns rows that match in both tables. LEFT JOIN returns all rows from the left table and NULLs where the right table has no match.
A primary key uniquely identifies a row and cannot be null. A foreign key references a primary key in another table and enforces that the referenced row exists.
SELECT col, COUNT(*) FROM t GROUP BY col HAVING COUNT(*) > 1.
NULL means unknown, so comparisons with = are never true. Use IS NULL or IS NOT NULL.
It lets the database find rows by a column without scanning the whole table. It speeds reads and slightly slows writes; add indexes on columns used in WHERE and JOIN.
Practise out loud. Say each answer once as written, then again in your own words with your own number or story.
Have a number ready. "My SQL score is at benchmark on a timed test" is a stronger answer than "I am good at it". Take the test and quote the result.
More in Accounts and data