Most Asked SQL Interview Questions in Data Engineering Interviews

This blog covers the most frequently asked SQL interview questions for data engineering roles. It includes real-world scenarios, optimised query techniques, and essential SQL topics every aspiring data engineer should master. Perfect for interview prep and skill boosting!

Vishal Barvaliya

6/8/20252 min read

SQL is the bread and butter of data engineering. Whether you are applying to a startup or a FAANG company, your ability to write optimized and correct SQL queries will be tested. This blog covers the most commonly asked SQL interview questions for data engineering roles—along with sample answers, explanations, and tips to crack them like a pro.

1. What is the difference between WHERE and HAVING clause?
  • WHERE filters rows before aggregation.

  • HAVING filters after aggregation.

Example

  • SELECT department, COUNT(*) as employee_count FROM employee_table WHERE status = 'active' GROUP BY department HAVING COUNT(*) > 10;

2. What is the difference between INNER JOIN and LEFT JOIN?
  • INNER JOIN returns only matching rows.

  • LEFT JOIN returns all rows from the left table and matching ones from the right.

3. How do you find the second-highest salary?
  • SELECT MAX(salary) AS second_highest FROM employee WHERE salary < (SELECT MAX(salary) FROM employee);

4. How do you find duplicates in a table?
  • SELECT name, COUNT(*) FROM employee GROUP BY name HAVING COUNT(*) > 1;

5. How would you delete duplicates but keep one?
  • DELETE FROM employee WHERE rowid NOT IN ( SELECT MIN(rowid) FROM employee GROUP BY name, department );

6. Difference between RANK(), DENSE_RANK(), and ROW_NUMBER()
  • RANK() skips numbers if there's a tie.

  • DENSE_RANK() doesn't skip numbers.

  • ROW_NUMBER() gives a unique number to each row.

7. What is a CTE (Common Table Expression)?

A CTE is a temporary result set that you can reference within a SELECT, INSERT, UPDATE, or DELETE.

  • WITH high_salary AS ( SELECT FROM employee WHERE salary > 100000 ) SELECT FROM high_salary WHERE department = 'Engineering';

8. What is a window function?

A function that performs a calculation across a set of rows related to the current row.

  • SELECT name, department, salary, RANK() OVER (PARTITION BY department ORDER BY salary DESC) as rank_in_dept FROM employee;

9. How to get the cumulative sum?
  • SELECT name, salary, SUM(salary) OVER (ORDER BY name) AS cumulative_salary FROM employee;

10. How do you find the department with the highest average salary?
  • SELECT department, AVG(salary) as avg_salary FROM employee GROUP BY department ORDER BY avg_salary DESC LIMIT 1;

Final Tips
  • Always use EXPLAIN to check query performance.

  • Normalize your database but also know when to denormalize.

  • Write readable queries—indent, alias properly, and use CTEs where necessary.

  • SQL interviews aren’t just about writing code—they’re about writing smart, scalable, and optimized queries. Practice these types of questions regularly and you’ll walk into your next interview with confidence!