← Back to Layerchecklist

SQL

Most real-world data starts in a database. Being able to pull exactly what you need with SQL is often the first step before any ML work even begins.

Interview mindset:

For every query: What table(s) do I need? What am I filtering, grouping, or joining? What would break if there are duplicates or NULLs?

SELECT & WHERE

The basic building blocks — choosing columns and filtering rows.

Interview check:Know the difference between filtering with WHERE(before grouping) and HAVING (after grouping).

SELECT name, age
  FROM users
  WHERE age > 25;
JOINs

Combine rows from two or more tables based on a related column.

Interview check:Know the difference between INNER, LEFT, and RIGHT joins — and what happens to unmatched rows in each.

SELECT orders.id, users.name
  FROM orders
  LEFT JOIN users
    ON orders.user_id = users.id;
GROUP BY & Aggregations

Groups rows sharing a value and computes something across each group — counts, sums, averages.

Interview check:Know why every non-aggregated column in SELECT must appear in GROUP BY.

SELECT department, AVG(salary)
  FROM employees
  GROUP BY department;
Subqueries

A query nested inside another — useful for filtering based on a computed value.

Interview check:Know when a subquery could be rewritten as a JOIN, and why that might be more efficient.

SELECT name FROM users
  WHERE id IN (
    SELECT user_id FROM orders
    WHERE total > 100
  );
Indexes

A data structure that speeds up lookups on a column, at the cost of extra storage and slower writes.

Interview check:Explain why indexes speed up reads but can slow down inserts/updates.

CREATE INDEX idx_user_id
  ON orders (user_id);

SQL Interview Questions You Should Be Able to Answer

  • What is the difference between WHERE and HAVING?
  • What is the difference between INNER JOIN and LEFT JOIN?
  • What does GROUP BY actually do?
  • When would you use a subquery instead of a JOIN?
  • What is an index, and what's the tradeoff of using one?
  • What is the difference between COUNT(*) and COUNT(column)?

The Standard You Want

You should be able to write a query from a plain-English question without hesitating, and explain what happens to your result if the data has duplicates or missing values.

A working query isn't enough — know why it returns exactly what it does.