Here are the most commonly asked SQL questions in delivery assessments — along
with exact queries and why they are asked.
1. Fetch all records from a table
Why asked: Basic SELECT understanding
Query
SELECT * FROM employees;
2. Get employees with salary greater than 50000
Why: Test filtering using WHERE
SELECT * FROM employees WHERE salary > 50000;
3. Get the highest salary from employees
Why: Aggregate function knowledge
SELECT MAX(salary) FROM employees;
4. Get total number of employees in each department
Why: Tests GROUP BY
SELECT department_id, COUNT(*) AS total_employees
FROM employees
GROUP BY department_id;
5. Get departments having more than 5 employees
Why: Combine GROUP BY with HAVING
SELECT department_id, COUNT(*) AS emp_count
FROM employees
GROUP BY department_id
HAVING COUNT(*) > 5;
6. Get names of employees who work in 'HR' or 'IT'
SELECT name FROM employees
WHERE department IN ('HR', 'IT');
7. Get employee names that start with 'A'
SELECT name FROM employees
WHERE name LIKE 'A%';
8. Sort employees by salary descending
SELECT * FROM employees
ORDER BY salary DESC;
9. Find duplicate values in a column (e.g., email)
SELECT email, COUNT(*)
FROM employees
GROUP BY email
HAVING COUNT(*) > 1;
10. Fetch top 3 salaries
-- MySQL
SELECT * FROM employees ORDER BY salary DESC LIMIT 3;
-- SQL Server
SELECT TOP 3 * FROM employees ORDER BY salary DESC;
11. Get the second highest salary
SELECT MAX(salary)
FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);
12. Find employees who do not have a manager
SELECT * FROM employees
WHERE manager_id IS NULL;
13. Inner join: employee and department
SELECT e.name, d.department_name
FROM employees e
JOIN departments d ON e.department_id = d.id;
14. Subquery: Find employees whose salary is above average
SELECT * FROM employees
WHERE salary > (SELECT AVG(salary) FROM employees);
15. Delete duplicate rows but keep one
DELETE FROM employees
WHERE id NOT IN (
SELECT MIN(id)
FROM employees
GROUP BY email
);
16. Find 2nd highest salary (can change 2 to any N):
sql
CopyEdit
SELECT MAX(salary)
FROM employees
WHERE salary < (
SELECT MAX(salary)
FROM employees
);