SQL and ETL interview preparation

Interviews for data engineering, ETL testing, data quality and analytics roles usually include a SQL round and a conversation about data warehouses and pipelines. The questions repeat in patterns, and it is much easier to prepare for patterns than for individual questions. This guide covers the SQL techniques that come up most often, with worked examples that you can run on any common database, followed by warehouse and pipeline concepts and a few testing-specific topics.

Set up a practice schema

Use these two tables to try every query below. Syntax differs slightly between databases (Oracle, PostgreSQL, SQL Server, Snowflake), so adjust function names where needed.

employees(emp_id, name, dept_id, salary, manager_id, hire_date)
departments(dept_id, dept_name)
orders(order_id, customer_id, order_date, amount, status)

Pattern 1: The nth highest value

A classic question is "find the second highest salary". There are several correct answers, and a good candidate can explain the trade-offs.

-- Window function: handles ties with DENSE_RANK
SELECT DISTINCT salary
FROM (
  SELECT salary, DENSE_RANK() OVER (ORDER BY salary DESC) AS rnk
  FROM employees
) t
WHERE rnk = 2;

-- Subquery without a window function
SELECT MAX(salary) FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);

Explain that RANK leaves gaps after ties, DENSE_RANK does not, and ROW_NUMBER gives a unique number to each row and so would skip a tied value. Mention what should happen if there is no second value.

Pattern 2: Finding duplicates and removing them

-- Which customers appear more than once for the same order date?
SELECT customer_id, order_date, COUNT(*) AS cnt
FROM orders
GROUP BY customer_id, order_date
HAVING COUNT(*) > 1;

-- Keep one row per group, using ROW_NUMBER
SELECT *
FROM (
  SELECT o.*, ROW_NUMBER() OVER (PARTITION BY order_id ORDER BY order_date DESC) AS rn
  FROM orders o
) t
WHERE rn = 1;

For data testers, duplicates are a favourite topic. Be ready to explain how you would check for duplicates on a business key, how you would decide which duplicate to keep, and how to confirm that a pipeline does not create them on a re-run.

Pattern 3: Joins and what each one returns

Know the difference between inner, left, right and full outer joins, and be able to say what each returns when keys do not match. A common follow-up is to find rows in one table that have no match in another:

-- Employees with no department record
SELECT e.emp_id, e.name
FROM employees e
LEFT JOIN departments d ON d.dept_id = e.dept_id
WHERE d.dept_id IS NULL;

Remember that a condition on the right-hand table placed in the WHERE clause can turn a left join into an inner join, and that NULL never equals NULL in a comparison.

Pattern 4: Aggregation by group and filtering groups

-- Departments whose average salary is above 60000
SELECT dept_id, AVG(salary) AS avg_salary
FROM employees
GROUP BY dept_id
HAVING AVG(salary) > 60000;

State clearly that WHERE filters rows before grouping and HAVING filters groups after it.

Pattern 5: Top n per group

-- Top 3 earners in each department
SELECT dept_id, name, salary
FROM (
  SELECT dept_id, name, salary,
         ROW_NUMBER() OVER (PARTITION BY dept_id ORDER BY salary DESC) AS rn
  FROM employees
) t
WHERE rn <= 3;

Pattern 6: Running totals and comparisons with the previous row

SELECT order_date,
       amount,
       SUM(amount) OVER (ORDER BY order_date) AS running_total,
       LAG(amount) OVER (ORDER BY order_date) AS previous_amount
FROM orders;

Window functions are tested heavily. Be able to explain PARTITION BY, ORDER BY inside a window, and the default frame that decides which rows a running total includes.

Pattern 7: Hierarchies and recursion

-- All reports under a manager (recursive CTE)
WITH RECURSIVE team AS (
  SELECT emp_id, name, manager_id FROM employees WHERE emp_id = 100
  UNION ALL
  SELECT e.emp_id, e.name, e.manager_id
  FROM employees e JOIN team t ON e.manager_id = t.emp_id
)
SELECT * FROM team;

Oracle uses CONNECT BY, and SQL Server omits the word RECURSIVE. Mention that you would check for cycles.

Pattern 8: Data validation queries

For ETL and QA roles, interviewers want to see how you prove that data moved correctly. A basic reconciliation approach compares counts, sums and sample rows:

-- Rows in source but missing in target
SELECT * FROM source_table
EXCEPT   -- MINUS in Oracle
SELECT * FROM target_table;

-- Compare row counts and a numeric checksum
SELECT COUNT(*), SUM(amount) FROM source_table;
SELECT COUNT(*), SUM(amount) FROM target_table;

Go beyond counts: check nulls, data types, truncation, rounding, time zones, character encoding, and boundary values. Explain how you would test a transformation rule from the specification, including negative cases.

Data warehouse concepts to know

Pipeline and platform topics

Testing-specific questions

How to practise

  1. Create the tables above in a free local database and write each query from memory.
  2. Change the data to include duplicates, nulls and ties, and check that your queries still behave correctly.
  3. Explain each solution aloud as though to an interviewer, including the alternatives and their limits.
  4. Time yourself. Many interview problems expect a working query in ten to fifteen minutes.
  5. Prepare two stories from real projects about data quality, using the structure in Prepare for an interview with evidence.

If you are updating your resume for these roles, see the resume guide for testers, QA and data engineers.

About this guide. General career information written by the EulrRise team. It is not legal, financial or employment advice. Verify job details and your own contract terms with the employer before sharing sensitive information or making decisions.

Related guides

All career guides · How EulrRise job alerts work