HomebaseWorks

SQL interview questions

The standard SQL questions for data, analyst and backend roles, with short answers and the rule behind each.

EWritten by the HomebaseWorks editorial team · reviewed 26 Oct 2026
1
What is the difference between WHERE and HAVING?

WHERE filters rows before grouping; HAVING filters groups after GROUP BY, usually on an aggregate such as COUNT or SUM.

2
Explain INNER JOIN versus LEFT JOIN.

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.

3
What is a primary key? A foreign key?

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.

Advertisement
4
How do you find duplicate values in a column?

SELECT col, COUNT(*) FROM t GROUP BY col HAVING COUNT(*) > 1.

5
Why does WHERE col = NULL return nothing?

NULL means unknown, so comparisons with = are never true. Use IS NULL or IS NOT NULL.

6
What does an index do?

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.

Advertisement
Continue with SQL4 lessons · 2 interview sets · 1 test · 1 certificate
Not tested

More in Accounts and data