Interview Questions

SQL Interview Questions Every Developer Should Practise

6 min read R Square IT Support TeamSample article

Joins, GROUP BY, the classic “second highest salary” and window functions — practise these SQL questions before your next interview.

Whether you are a Java Full Stack or MEAN Stack developer, SQL rounds are common. These questions appear again and again — practise writing them by hand.

1. Second highest salary

sql
SELECT MAX(salary) AS second_highest
FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);

2. Nth highest salary with a window function

sql
SELECT salary
FROM (
  SELECT salary, DENSE_RANK() OVER (ORDER BY salary DESC) AS rnk
  FROM employees
) ranked
WHERE rnk = 3;

3. Departments with more than five employees

sql
SELECT department_id, COUNT(*) AS employee_count
FROM employees
GROUP BY department_id
HAVING COUNT(*) > 5;

What is the difference between WHERE and HAVING?

WHERE filters rows before grouping; HAVING filters groups after aggregation.

4. Find duplicate emails

sql
SELECT email, COUNT(*)
FROM users
GROUP BY email
HAVING COUNT(*) > 1;

INNER JOIN vs LEFT JOIN?

INNER JOIN returns only matching rows from both tables. LEFT JOIN returns all rows from the left table, with NULLs where the right table has no match.

  • SQL
  • Interview
  • Database

This is a sample article published as a starter resource. Verify technical details against official documentation for the versions you use.

Prepare. Perform. Progress.

Want personal guidance on this topic?

Our team can help you prepare, solve doubts and practise interviews around what you are learning.

Chat with us