SQL interview questions test if you can pull the right rows out of a database with clean, correct queries. Most rounds focus on five skills: joins, GROUP BY with HAVING, subqueries, window functions and a sense of what makes a query slow. So if you can write those from memory and explain your logic, you will pass most analyst, backend and data engineering screens.
SQL is also one of the most used languages in tech. In the Stack Overflow Developer Survey published in October 2026, 58% of respondents used SQL, level with Python and just behind JavaScript at 62%.
All 60 questions use the same four sample tables, so you can run every answer yourself. After the questions, a table shows the syntax differences between MySQL, PostgreSQL and SQL Server. Then comes a list of the mistakes that cost candidates the most points.
Sample Tables Used in the Answers
Every query that follows runs against these four tables. So create them in PostgreSQL or MySQL, add 20 or 30 rows of your own, and test each answer as you read.
CREATE TABLE departments (
dept_id INT PRIMARY KEY,
dept_name VARCHAR(50) NOT NULL
);
CREATE TABLE employees (
emp_id INT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(100),
dept_id INT,
manager_id INT,
salary DECIMAL(10,2),
hire_date DATE,
FOREIGN KEY (dept_id) REFERENCES departments(dept_id),
FOREIGN KEY (manager_id) REFERENCES employees(emp_id)
);
CREATE TABLE customers (
customer_id INT PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(100),
city VARCHAR(50)
);
CREATE TABLE orders (
order_id INT PRIMARY KEY,
customer_id INT NOT NULL,
order_date DATE NOT NULL,
amount DECIMAL(10,2) NOT NULL,
FOREIGN KEY (customer_id) REFERENCES customers(customer_id)
);
If you want a desktop tool to browse these tables, our TablePlus vs DBeaver comparison covers a paid and a free option.
SQL Basics and Filtering Questions
These open almost every SQL screen. They look easy, but each one has a trap that interviewers like to test.
1. What is SQL?
SQL, or Structured Query Language, is the standard language for working with relational databases. You use it to read, add, change and delete data, and to define tables. It is declarative, so you describe the result you want and the database decides how to get it.
2. What is the difference between SQL and MySQL?
SQL is the language. MySQL is one database product that understands it. PostgreSQL, SQL Server, Oracle and SQLite are other products. Each adds its own extras to standard SQL, so small parts of the syntax differ.
3. In what order does a SELECT query run?
The clauses run in a different order from how you write them. The logical order begins with FROM and JOIN, then WHERE. Next come GROUP BY, HAVING, SELECT and DISTINCT, and last ORDER BY and LIMIT. That is why you cannot use a column alias from SELECT inside WHERE, but you can use it in ORDER BY.
4. What is the difference between WHERE and HAVING?
WHERE filters rows before they are grouped. HAVING filters groups after aggregation. So you use WHERE for row conditions and HAVING for conditions on COUNT, SUM or AVG.
SELECT dept_id, AVG(salary) AS avg_salary
FROM employees
WHERE hire_date >= '2020-01-01'
GROUP BY dept_id
HAVING AVG(salary) > 60000;
5. What does DISTINCT do?
DISTINCT removes duplicate rows from the result. It applies to the whole row, so every selected column counts. For example, SELECT DISTINCT dept_id, manager_id keeps each unique pair. If you only need unique values of one column, select just that column.
6. How does ORDER BY sort NULL values?
It depends on the database. PostgreSQL treats NULL as larger than any value, so NULLs come last in ascending order. MySQL and SQL Server put NULLs first in ascending order. PostgreSQL also lets you say NULLS FIRST or NULLS LAST to control it.
7. How do you find names that begin with a certain letter?
Use LIKE with the % wildcard, which matches any run of characters. The _ wildcard, by contrast, matches exactly one character.
SELECT name FROM employees WHERE name LIKE 'A%';
SELECT name FROM employees WHERE name LIKE '_a%'; -- second letter is a
Case rules differ. MySQL’s default collations ignore case, while PostgreSQL’s LIKE is case-sensitive, so you use ILIKE there to ignore case.
8. What is the difference between IN and BETWEEN?
IN matches any value in a list, like dept_id IN (1, 3, 5). BETWEEN matches a range and includes both ends. Be careful with dates and times. order_date BETWEEN '2026-01-01' AND '2026-01-31' works for a DATE column, but on a timestamp it misses most of January 31.
9. How do you check for NULL values?
Use IS NULL or IS NOT NULL. A test like salary = NULL never returns true, because any compare with NULL gives unknown.
SELECT name FROM employees WHERE manager_id IS NULL; -- top boss
SELECT name, COALESCE(email, 'no email') FROM employees;
10. What do COALESCE and NULLIF do?
COALESCE returns the first non-NULL value in its list, so it is handy for defaults. NULLIF(a, b) returns NULL when a equals b, and a otherwise. A common use is avoiding divide-by-zero errors: total / NULLIF(count, 0).
SQL Join Questions
Joins are the most tested topic in SQL rounds, so expect at least two join questions, and expect the interviewer to ask what happens to unmatched rows.
11. How does an INNER JOIN work?
An inner join returns only rows that match in both tables. So employees with no department, or departments with no employees, are left out.
SELECT e.name, d.dept_name
FROM employees e
INNER JOIN departments d ON e.dept_id = d.dept_id;
12. How do you list every department with its employee count, including empty ones?
Use a LEFT JOIN from departments, then count a column from the employee side. COUNT(e.emp_id) skips NULLs, so empty departments show 0.
SELECT d.dept_name, COUNT(e.emp_id) AS staff
FROM departments d
LEFT JOIN employees e ON e.dept_id = d.dept_id
GROUP BY d.dept_name;
COUNT(*) would be a classic mistake in this query. It counts the one NULL row, so empty departments show 1.
13. When would you use a RIGHT JOIN?
A right join keeps every row from the right table. It is the mirror of a left join, so you can always rewrite it as a left join by swapping the table order. Most teams stick to left joins for readability.
14. How do you do a FULL OUTER JOIN in MySQL?
A full outer join keeps all rows from both tables. PostgreSQL and SQL Server support FULL OUTER JOIN, but MySQL does not. In MySQL, combine a left join and a right join with UNION.
SELECT e.name, d.dept_name
FROM employees e LEFT JOIN departments d ON e.dept_id = d.dept_id
UNION
SELECT e.name, d.dept_name
FROM employees e RIGHT JOIN departments d ON e.dept_id = d.dept_id;
15. What is a CROSS JOIN?
A cross join returns every pair of rows from the two tables. If one table has 4 sizes and the other has 5 colors, you get 20 rows. It is useful for building grids, such as every store with every date, but dangerous on big tables.
16. How do you show each employee next to their manager’s name?
Join the table to itself with a self join. Use a left join so the top boss, who has no manager, still appears.
SELECT e.name AS employee, m.name AS manager
FROM employees e
LEFT JOIN employees m ON e.manager_id = m.emp_id;
17. How do you find customers who have never placed an order?
This is called an anti join, so write it with NOT EXISTS, the safest form.
SELECT c.customer_id, c.name
FROM customers c
WHERE NOT EXISTS (
SELECT 1 FROM orders o WHERE o.customer_id = c.customer_id
);
Also, a LEFT JOIN with WHERE o.order_id IS NULL gives the same result.
18. Why can NOT IN return no rows at all?
If the subquery returns even one NULL, NOT IN returns nothing. The check x NOT IN (1, 2, NULL) becomes x <> 1 AND x <> 2 AND x <> NULL. That last part is unknown, so the whole test fails. So prefer NOT EXISTS, or filter NULLs out of the subquery.
19. What is the difference between UNION and UNION ALL?
UNION stacks two result sets and removes duplicates. UNION ALL keeps every row. Removing duplicates needs a sort or a hash step, so UNION ALL is faster. Use it when you know no rows repeat, or when you want to keep the repeats.
20. Does it matter if a filter goes in ON or in WHERE with a LEFT JOIN?
Yes. A filter in the ON clause only limits which right-side rows match, so every left row stays. The same filter in WHERE runs after the join and drops left rows with no match, which turns your left join into an inner join.
-- keeps all customers, shows only 2026 orders
SELECT c.name, o.order_id
FROM customers c
LEFT JOIN orders o
ON o.customer_id = c.customer_id AND o.order_date >= '2026-01-01';
Read also: 200 Angular Interview Questions With Short Answers
GROUP BY and Aggregate Questions
Aggregates sit behind almost every report, so analyst rounds lean hard on this group. Write each query, then say out loud what one output row means.
21. What is the difference between COUNT(*), COUNT(column) and COUNT(DISTINCT column)?
COUNT(*) counts all rows. COUNT(email) counts rows where email is not NULL. COUNT(DISTINCT email) counts unique non-NULL emails. So on a table of 100 rows where 10 emails are NULL and 5 repeat, you could get 100, 90 and 85.
22. What is the main rule of GROUP BY?
Every column in SELECT must either be in GROUP BY or sit inside an aggregate like SUM. Otherwise the database does not know which value to show for the group. MySQL enforces this by default through its ONLY_FULL_GROUP_BY mode.
23. How do you find the average salary per department, highest first?
SELECT d.dept_name, ROUND(AVG(e.salary), 2) AS avg_salary
FROM employees e
JOIN departments d ON d.dept_id = e.dept_id
GROUP BY d.dept_name
ORDER BY avg_salary DESC;
24. How do you find departments with more than five employees?
Group by department and filter with HAVING, since the condition is on a count.
SELECT dept_id, COUNT(*) AS staff
FROM employees
GROUP BY dept_id
HAVING COUNT(*) > 5;
25. How do you total sales by month?
Turn each date into its month, then group by it. The function differs by database.
-- PostgreSQL
SELECT DATE_TRUNC('month', order_date) AS month, SUM(amount) AS sales
FROM orders GROUP BY 1 ORDER BY 1;
-- MySQL
SELECT DATE_FORMAT(order_date, '%Y-%m') AS month, SUM(amount) AS sales
FROM orders GROUP BY month ORDER BY month;
26. How do you find duplicate emails?
Group by the email, then keep groups with more than one row.
SELECT email, COUNT(*) AS copies
FROM customers
GROUP BY email
HAVING COUNT(*) > 1;
27. How do you delete duplicate rows but keep one copy?
Keep the row with the lowest ID and delete the rest. However, the syntax differs by database.
-- PostgreSQL
DELETE FROM customers a
USING customers b
WHERE a.email = b.email AND a.customer_id > b.customer_id;
-- MySQL
DELETE c1 FROM customers c1
JOIN customers c2
ON c1.email = c2.email AND c1.customer_id > c2.customer_id;
Run it as a SELECT first, inside a transaction, to see what will go.
28. How do you show each department’s share of the total salary bill?
Use a window function over the grouped result, so you can divide each group’s sum by the grand total.
SELECT dept_id,
SUM(salary) AS dept_total,
ROUND(100.0 * SUM(salary) / SUM(SUM(salary)) OVER (), 1) AS pct
FROM employees
GROUP BY dept_id;
Subquery and CTE Questions
These questions check if you can break a hard problem into steps. Name each step out loud as you write it.
29. What kinds of subqueries are there?
A scalar subquery returns one value and can sit in SELECT or WHERE. A row or table subquery returns many rows and goes after IN, EXISTS or in FROM as a derived table. A correlated subquery refers to the outer query and runs per outer row, at least in theory.
30. How do you find employees who earn more than their department’s average?
Use a correlated subquery, because it computes the average for the current row’s department.
SELECT e.name, e.salary, e.dept_id
FROM employees e
WHERE e.salary > (
SELECT AVG(x.salary) FROM employees x WHERE x.dept_id = e.dept_id
);
31. When do you use EXISTS and when IN?
EXISTS stops at the first match and handles NULLs safely, so it works well for “has at least one” checks. IN reads better for short fixed lists. Modern optimizers often run both the same way for positive checks. For the negative case, NOT EXISTS is safer than NOT IN.
32. What is a CTE?
A CTE, or common table expression, is a named temporary result you define with WITH at the top of a query. It makes long queries easier to read, because each step gets a name. You can refer to it more than once in the main query.
WITH dept_avg AS (
SELECT dept_id, AVG(salary) AS avg_sal
FROM employees GROUP BY dept_id
)
SELECT e.name, e.salary, a.avg_sal
FROM employees e JOIN dept_avg a ON a.dept_id = e.dept_id
WHERE e.salary > a.avg_sal;
33. How do you list everyone who reports to a manager, at every level?
Use a recursive CTE. The first part picks the starting manager, and the second part keeps joining to find their reports.
WITH RECURSIVE team AS (
SELECT emp_id, name, manager_id, 1 AS level
FROM employees WHERE emp_id = 1
UNION ALL
SELECT e.emp_id, e.name, e.manager_id, t.level + 1
FROM employees e JOIN team t ON e.manager_id = t.emp_id
)
SELECT * FROM team;
PostgreSQL and MySQL need the word RECURSIVE, while SQL Server uses plain WITH.
34. How do you find the second highest salary?
There are three common ways. The first works everywhere, and the window version is the easiest to extend.
-- 1. Subquery
SELECT MAX(salary) FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);
-- 2. DENSE_RANK
SELECT DISTINCT salary FROM (
SELECT salary, DENSE_RANK() OVER (ORDER BY salary DESC) AS rnk
FROM employees
) t WHERE rnk = 2;
-- 3. LIMIT with OFFSET (MySQL, PostgreSQL)
SELECT DISTINCT salary FROM employees
ORDER BY salary DESC LIMIT 1 OFFSET 1;
35. How do you find the Nth highest salary?
Use DENSE_RANK and filter on N. DENSE_RANK makes ties share a rank with no gaps, so N always means the Nth distinct salary. If no Nth salary exists, the query returns no rows. So be ready to show how you would return NULL in that case.
36. How do you find employees who earn more than their manager?
Self join the table, then compare the two salaries.
SELECT e.name, e.salary, m.name AS manager, m.salary AS manager_salary
FROM employees e
JOIN employees m ON e.manager_id = m.emp_id
WHERE e.salary > m.salary;
Window Function Questions
Window functions set skilled candidates apart in data roles. So practice these until you can write them without notes.
37. What is a window function?
A window function computes a value across a set of rows related to the current row, but it keeps every row in the output. That is the big difference from GROUP BY, which squashes rows into one per group. You define the window with OVER, using PARTITION BY and ORDER BY.
38. What is the difference between ROW_NUMBER, RANK and DENSE_RANK?
All three number rows in order, but they differ on ties. For salaries of 100, 100 and 90, ROW_NUMBER gives 1, 2, 3. RANK gives 1, 1, 3 and leaves a gap. DENSE_RANK gives 1, 1, 2 with no gap.
39. How do you get the top three earners in each department?
Rank inside each department, then filter in an outer query. You cannot filter on a window function in WHERE of the same query.
SELECT * FROM (
SELECT name, dept_id, salary,
DENSE_RANK() OVER (PARTITION BY dept_id ORDER BY salary DESC) AS rnk
FROM employees
) t
WHERE rnk <= 3;
40. How do you compute a running total?
Use SUM as a window function, then order it by date.
SELECT order_date, amount,
SUM(amount) OVER (ORDER BY order_date, order_id
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS running_total
FROM orders;
Adding order_id breaks ties. Also, the ROWS frame stops rows with the same date from being summed together.
41. How do you compare each month’s sales with the month before?
Group by month in a CTE, then use LAG to pull the previous month’s value onto the same row. This version uses PostgreSQL’s DATE_TRUNC.
WITH monthly AS (
SELECT DATE_TRUNC('month', order_date) AS month, SUM(amount) AS sales
FROM orders GROUP BY 1
)
SELECT month, sales,
sales - LAG(sales) OVER (ORDER BY month) AS change
FROM monthly;
LEAD does the same for the next row.
42. How do you calculate a seven-day moving average?
Use AVG with a frame of the current row and the six before it. The example uses a daily_sales table with one row per day, so fill in missing days first if your data has gaps.
SELECT day, sales,
AVG(sales) OVER (ORDER BY day ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) AS avg_7d
FROM daily_sales;
43. How do you get each customer’s first order?
Number each customer’s orders by date, then keep number 1.
SELECT * FROM (
SELECT o.*, ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY order_date, order_id) AS rn
FROM orders o
) t WHERE rn = 1;
44. What does NTILE do?
NTILE(n) splits ordered rows into n groups of near-equal size and labels each row with its group number. For example, NTILE(4) OVER (ORDER BY amount) puts orders into quartiles, so you can find the top 25% of orders by value.
45. How do you find users who logged in on three or more days in a row?
This is the “gaps and islands” problem. First, subtract a row number from each date. Dates in an unbroken run end up with the same result, which marks the island. This PostgreSQL version uses a logins table with one row per user per day.
WITH runs AS (
SELECT user_id, login_date,
login_date - CAST(ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY login_date) AS INT) AS grp
FROM logins
)
SELECT user_id, MIN(login_date) AS run_start, COUNT(*) AS days
FROM runs
GROUP BY user_id, grp
HAVING COUNT(*) >= 3;
46. What is the difference between PARTITION BY and GROUP BY?
GROUP BY returns one row per group. PARTITION BY inside OVER splits rows into groups for the window function but returns every row. So use PARTITION BY when you need group totals next to row-level detail, such as each salary next to its department average.
Data Change and Table Design Questions
Backend and data engineering roles ask these more often than analyst roles. However, everyone should know the first two.
47. What is the difference between DELETE, TRUNCATE and DROP?
DELETE removes chosen rows, fires triggers and can be rolled back. TRUNCATE removes all rows fast. In MySQL, TRUNCATE causes an implicit commit and resets AUTO_INCREMENT, so you cannot roll it back. In PostgreSQL, TRUNCATE can be rolled back inside a transaction. DROP removes the whole table, structure and all.
48. How do you copy rows from one table into another?
Use INSERT INTO ... SELECT. However, the column lists must line up in count and type.
INSERT INTO orders_archive (order_id, customer_id, order_date, amount)
SELECT order_id, customer_id, order_date, amount
FROM orders
WHERE order_date < '2024-01-01';
49. How do you update rows using data from another table?
The syntax differs. MySQL puts the join after UPDATE, and PostgreSQL uses a FROM clause.
-- MySQL: 10% raise for the Sales team
UPDATE employees e
JOIN departments d ON d.dept_id = e.dept_id
SET e.salary = e.salary * 1.10
WHERE d.dept_name = 'Sales';
-- PostgreSQL
UPDATE employees e
SET salary = e.salary * 1.10
FROM departments d
WHERE d.dept_id = e.dept_id AND d.dept_name = 'Sales';
50. How do you insert a row, or update it if it already exists?
This is called an upsert. For example, PostgreSQL uses ON CONFLICT, MySQL uses ON DUPLICATE KEY UPDATE, and SQL Server uses MERGE.
-- PostgreSQL
INSERT INTO customers (customer_id, name, city)
VALUES (7, 'Asha Rao', 'Pune')
ON CONFLICT (customer_id) DO UPDATE SET city = EXCLUDED.city;
-- MySQL
INSERT INTO customers (customer_id, name, city)
VALUES (7, 'Asha Rao', 'Pune')
ON DUPLICATE KEY UPDATE city = VALUES(city);
Newer MySQL versions prefer a row alias over VALUES() in that last line, so mention it if the interviewer uses MySQL.
51. How do you add a column or a rule to an existing table?
Use ALTER TABLE. On a big table, a new column with a default or a new constraint can lock the table. So do it in a quiet hour, or use your database’s online change options.
ALTER TABLE employees ADD COLUMN phone VARCHAR(20);
ALTER TABLE employees ADD CONSTRAINT chk_salary CHECK (salary > 0);
52. How do you run several changes as one transaction?
Wrap them in BEGIN and COMMIT. If anything fails, run ROLLBACK and nothing is saved. The example moves money between rows of an accounts table.
BEGIN;
UPDATE accounts SET balance = balance - 500 WHERE id = 1;
UPDATE accounts SET balance = balance + 500 WHERE id = 2;
COMMIT;
Also, SQL Server uses BEGIN TRANSACTION, and MySQL accepts both BEGIN and START TRANSACTION.
53. What is a view, and when would you create one?
A view is a saved SELECT that you query like a table. Create one to hide a long join, to give a team a stable shape even if base tables change, or to expose only some columns. A plain view stores no data, so it is only as fast as its query.
54. How do you turn values into labels or columns with CASE?
CASE returns a value based on conditions, like an if-else. Inside an aggregate, it also pivots rows into columns.
SELECT name,
CASE WHEN salary >= 100000 THEN 'High'
WHEN salary >= 50000 THEN 'Mid'
ELSE 'Entry' END AS band
FROM employees;
SELECT customer_id,
SUM(CASE WHEN EXTRACT(YEAR FROM order_date) = 2024 THEN amount ELSE 0 END) AS sales_2024,
SUM(CASE WHEN EXTRACT(YEAR FROM order_date) = 2026 THEN amount ELSE 0 END) AS sales_2026
FROM orders GROUP BY customer_id;
Query Speed and Index Questions
Senior rounds almost always end here. So bring one real example of a slow query you made fast.
55. How does an index make a query faster?
An index is a sorted structure, usually a B-tree, that lets the database jump to matching rows without scanning the whole table. For example, an index on orders(customer_id) turns a search through ten million orders into a few quick lookups. In PostgreSQL, CREATE INDEX makes a B-tree unless you ask for another type.
CREATE INDEX idx_orders_customer ON orders (customer_id);

56. Why might a query ignore an index?
The most common cause is a function wrapped around the indexed column. A pattern like LIKE '%bar', with a wildcard at the front, also blocks the index. So do a type mismatch that forces a cast and a filter that matches most of the table. Out-of-date table stats can also lead the planner to a bad choice.
57. What does SARGable mean, and how do you fix a query that is not?
A SARGable condition is one the database can use an index for. Wrapping the column in a function usually breaks this. So rewrite the filter as a range on the bare column.
-- Not SARGable
SELECT * FROM orders WHERE YEAR(order_date) = 2026;
-- SARGable
SELECT * FROM orders
WHERE order_date >= '2026-01-01' AND order_date < '2027-01-01';
58. How do you read a query plan?
Run EXPLAIN before the query to see the plan. In PostgreSQL, EXPLAIN ANALYZE also runs it and shows real times and row counts. Look for sequential scans on large tables, nested loops over many rows, big sorts, and estimated rows that are far from actual rows.
59. How do you return only the first few rows?
MySQL and PostgreSQL use LIMIT. SQL Server uses TOP. The SQL standard form is FETCH FIRST, which PostgreSQL and Oracle support. Always add ORDER BY, or “first” has no fixed meaning.
SELECT * FROM orders ORDER BY amount DESC LIMIT 10; -- MySQL, PostgreSQL
SELECT TOP 10 * FROM orders ORDER BY amount DESC; -- SQL Server
SELECT * FROM orders ORDER BY amount DESC FETCH FIRST 10 ROWS ONLY; -- standard
60. Why is OFFSET slow for deep pages, and what do you use instead?
OFFSET 100000 makes the database read and throw away 100,000 rows before it returns the page. Keyset pagination is faster. You remember the last value you showed and ask for rows after it, which an index can serve directly.
SELECT order_id, order_date, amount
FROM orders
WHERE order_id > 50120 -- last id on the previous page
ORDER BY order_id
LIMIT 20;
Syntax Differences Between MySQL, PostgreSQL and SQL Server
Interviewers often let you pick a dialect, but they notice if you mix them up. The table covers the differences that come up most in SQL rounds.
| Task | MySQL | PostgreSQL | SQL Server |
|---|---|---|---|
| First 10 rows | LIMIT 10 | LIMIT 10 | TOP 10 |
| Value if NULL | IFNULL() or COALESCE() | COALESCE() | ISNULL() or COALESCE() |
| Today’s date | CURDATE() | CURRENT_DATE | CAST(GETDATE() AS DATE) |
| Auto number column | AUTO_INCREMENT | GENERATED AS IDENTITY | IDENTITY(1,1) |
| Insert or update | ON DUPLICATE KEY UPDATE | ON CONFLICT DO UPDATE | MERGE |
| Full outer join | Not built in | FULL JOIN | FULL JOIN |
| Case-blind LIKE | Default in most collations | ILIKE | Default in most collations |
If you get to choose, PostgreSQL is the best pick for practice, because it follows the standard closely and its errors are easy to read. It is not the right pick if the job ad names SQL Server, since T-SQL has its own habits like TOP and ISNULL. In that case, practice in SQL Server Express.
Read also: 100 Database Questions for Interview
Mistakes That Cost Points in SQL Rounds
Most failed SQL rounds come down to a handful of bad habits. So watch for these as you practice.
- Typing before you plan. State what one output row means first, such as “one row per department”, and then write the query.
- Using
COUNT(*)after aLEFT JOIN, which counts the NULL row and turns zero into one. - Trusting
NOT IN, since one NULL in the subquery wipes out every row. - Putting a filter on the right table of a
LEFT JOINinWHERE, which quietly makes it an inner join. - Ignoring ties. Ask if two people with the same salary should share a rank, then pick
RANK,DENSE_RANKorROW_NUMBERto match. - Skipping edge cases. Explain what your query does with NULLs, empty tables and duplicate rows before the interviewer asks.
Most SQL tests also run on a timer, and you may face many of them. Our look at the average number of job applications before getting hired helps you plan for that.
Quick Answers About SQL Interview Prep
How many SQL questions should I practice before an interview?
For most analyst and backend roles, 50 to 80 hands-on problems is enough. Just make sure they cover joins, totals, subqueries and window functions. Also, do them on a real database so you see the errors as they happen.
Is SQL enough to get a data analyst job?
SQL is the core skill. But most analyst jobs also want Excel and one chart tool, such as Power BI or Tableau. Our guide on becoming a data analyst without a degree lays out the rest of the skill set.
Do interviewers care which database I use?
Mostly no, as long as your logic is sound. Say which one you use at the start, so small syntax gaps do not look like mistakes. But if the job uses one product, learn its date functions and how it limits rows.
What is the hardest SQL topic in interviews?
For most people, it is window functions with custom frames. Recursive CTEs come next. Both show up in senior data rounds. So practice running totals, moving averages and gaps and islands until you can write them from memory.




















































































































