Database
Top SQL Interview Queries
Master these common SQL queries to confidently tackle database rounds in technical interviews.
0%
Progress
0 / 34 solved
1.Retrieve all columns from the 'employees' table.
Easy
2.Find the distinct departments from the 'employees' table.
Easy
3.Find all employees who have a salary greater than 50,000.
Easy
4.Find all employees hired in the year 2023.
Easy
5.Find employees whose name starts with 'A'.
Easy
6.Count the total number of employees in the company.
Easy
7.Find the maximum salary from the 'employees' table.
Easy
8.Find the average salary of employees in each department.
Easy
9.Sort employees by salary in descending order.
Easy
10.Find the second highest salary in the 'employees' table.
Medium
11.Find employees earning more than the average salary.
Medium
12.Find the number of employees in each department, but only show departments with more than 5 employees.
Medium
13.Fetch employee names along with their department names (using JOIN).
Medium
14.Fetch all employees and their departments, including employees without a department.
Medium
15.Find duplicate email addresses in the 'users' table.
Medium
16.Find employees who do not belong to any department.
Easy
17.Get the top 3 highest paid employees.
Easy
18.Find the third highest salary using LIMIT and OFFSET.
Medium
19.Find employees who are earning the exact same salary.
Medium
20.Rank employees by salary within each department.
Hard
21.Find the highest paid employee in each department.
Hard
22.Compare each employee's salary with the previous employee's salary in the same department.
Hard
23.Find the Nth highest salary (e.g., N=4) without using LIMIT.
Hard
24.Delete duplicate rows based on email, keeping the one with the lowest ID.
Hard
25.Find employees who earn more than their managers.
Medium
26.Swap the gender values ('M' to 'F' and 'F' to 'M') in a single update statement.
Medium
27.Calculate the cumulative sum of sales by date.
Hard
28.Find the first and last name of employees along with their job title, handle NULL titles as 'N/A'.
Easy
29.Get all combinations of products and colors (Cartesian product).
Medium
30.Find the difference in days between the hire date of the current employee and the next hired employee.
Hard
31.Find departments that have no employees.
Medium
32.Pivot rows to columns: Count males and females in a single row.
Medium
33.Find active users from the last 30 days.
Easy
34.Update multiple rows with different values using CASE.
Medium