Back to the blog

SQL Interview Questions That Actually Get Asked (With Answers)

The handful of SQL questions that show up in almost every data interview — with clean answers and the one preparation method that works.

By Sara Khan2 min read

Landing a data role almost always comes down to one thing: can you write SQL under pressure? The good news is that SQL interviews are remarkably predictable. The same concepts come up again and again. Master these and you'll walk in calm and prepared.

The questions you'll almost certainly get

1. What's the difference between INNER JOIN and LEFT JOIN?

An INNER JOIN returns only rows that match in both tables. A LEFT JOIN returns every row from the left table, filling in NULL where there's no match on the right.

-- All customers, even those who never ordered:
SELECT c.name, o.id AS order_id
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.id;

2. How do you find duplicate rows?

SELECT email, COUNT(*) AS occurrences
FROM users
GROUP BY email
HAVING COUNT(*) > 1;

3. What's the difference between WHERE and HAVING?

WHERE filters rows before aggregation; HAVING filters groups after aggregation. This trips up a surprising number of candidates.

4. Find the second-highest salary

A classic. The cleanest modern answer uses a window function:

SELECT DISTINCT salary
FROM (
  SELECT salary, DENSE_RANK() OVER (ORDER BY salary DESC) AS rnk
  FROM employees
) ranked
WHERE rnk = 2;

5. What is a window function, and when would you use one?

Window functions compute across a set of rows related to the current row without collapsing them into groups. Use them for running totals, rankings, and period-over-period comparisons.

SELECT
  month,
  revenue,
  SUM(revenue) OVER (ORDER BY month) AS running_total
FROM monthly_sales;

How to actually prepare

Reading these answers is useful. But interviewers can tell within minutes whether you've typed SQL or merely read it. The only reliable preparation is repetition against real data until the syntax is automatic.

Turn preparation into proof

Here's a tip that works: walk into the interview already holding a credential that demonstrates these exact skills. SQLCertified drills every concept above through interactive, in-browser challenges, then certifies that you can do them. You get the practice and a verifiable certificate to put on your resume — so you're not just prepared, you're provably qualified.

Share this article

Comments

No comments yet

Sign in to join the conversation.

Sign in to comment

Be the first to comment.

More from the blog