Sign inStart free →

SQL interview guide: why it matters, core concepts, practice plan

5 December 2026 · giveinterview team

Why interviewers ask about it

SQL appears in 17 of today’s 90 new software roles. Companies ask because data is the backbone of most products. A candidate who can retrieve, aggregate, and transform data reliably demonstrates three things:

  1. Problem‑solving with real data – they can turn a business question into a query.
  2. Understanding of relational design – they know how tables relate, which affects performance and correctness.
  3. Ability to work with existing codebases – most legacy systems expose data through SQL, so a developer must read and modify queries daily.

Interviewers use SQL to gauge both theoretical knowledge (normal forms, joins) and practical skill (writing clear, efficient queries). Even for roles that focus on front‑end or systems programming, data‑driven decisions are common, so a baseline SQL competence is expected.

The core ideas

1. Relational fundamentals

2. Query building blocks

3. Joins

Understanding join order and join conditions is crucial for both correctness and performance.

4. Set operations

5. Window functions

6. Indexes and execution plans

7. Common pitfalls

A worked example

Task: A company stores user activity in two tables.

-- users table
CREATE TABLE users (
    user_id   INT PRIMARY KEY,
    email     VARCHAR(255) NOT NULL,
    signup_dt DATE NOT NULL
);

-- events table
CREATE TABLE events (
    event_id   INT PRIMARY KEY,
    user_id    INT REFERENCES users(user_id),
    event_type VARCHAR(50),
    event_ts   TIMESTAMP NOT NULL
);

Requirement: For each user who signed up in the last 30 days, list the total number of login events and the date of their most recent purchase event. Show users with zero logins as 0 and users with no purchases as NULL. Solution:

WITH recent_users AS (
    SELECT user_id, email
    FROM users
    WHERE signup_dt >= CURRENT_DATE - INTERVAL '30 day'
),
login_counts AS (
    SELECT user_id, COUNT(*) AS login_cnt
    FROM events
    WHERE event_type = 'login'
    GROUP BY user_id
),
last_purchase AS (
    SELECT user_id, MAX(event_ts) AS last_purchase_dt
    FROM events
    WHERE event_type = 'purchase'
    GROUP BY user_id
)
SELECT ru.user_id,
       ru.email,
       COALESCE(lc.login_cnt, 0) AS login_cnt,
       lp.last_purchase_dt
FROM recent_users ru
LEFT JOIN login_counts lc   ON ru.user_id = lc.user_id
LEFT JOIN last_purchase lp  ON ru.user_id = lp.user_id
ORDER BY ru.user_id;

Explanation:

  1. recent_users isolates the target cohort.
  2. login_counts aggregates login events per user.
  3. last_purchase finds the most recent purchase timestamp.
  4. Two LEFT JOINs keep every recent user, inserting 0 for missing login rows via COALESCE and leaving NULL for missing purchases.
  5. The final ORDER BY gives deterministic output.

5 questions you will be asked

  1. Explain the difference between INNER JOIN and LEFT JOIN.
  1. How would you find duplicate rows based on a column email in a users table?
  1. What is a window function and when is it preferable to GROUP BY?
  1. Describe how an index on events(user_id, event_ts) would affect the query in the worked example.
  1. **Why is SELECT discouraged in production code?*

Common mistakes

A 3‑day practice plan

Day 1 – Foundations

Day 2 – Joins and Window Functions

Day 3 – Performance and Edge Cases

By the end of the three days you will have reinforced the core ideas, seen how they appear in realistic tasks, and built a checklist of pitfalls to avoid during an interview.

Roles hiring for SQL now

Each has its own mock interview, built from the real job description.

More tech roles today

Practise it out loud

Knowing the answer is not the same as explaining it under follow-up questions. Try a free mock interview on giveinterview.com.

Practise it out loud

Reading helps. Saying it to an interviewer who asks follow-ups helps more.