SQL queries interview questions¶
🟢 LEVEL 1 — Basic SELECT
- Show all employees.
- Show only employee names and salary.
- Show employees with salary > 60000.
- Show employees hired after 2021.
- Show employees who work in department 1.
- Show unique department IDs from employees.
- Show employees sorted by salary descending.
- Show top 3 highest paid employees.
- Count total employees.
- Count female employees.
🟡 LEVEL 2 — WHERE + GROUP BY
- Count employees in each department.
- Average salary per department.
- Max salary in company.
- Min salary in company.
- Total salary paid by company.
- Count employees hired after 2020.
- Show departments having more than 2 employees.
- Show department with highest avg salary.
- Count employees by gender.
- Show employees whose name starts with 'S'.
🟠 LEVEL 3 — JOINS (Important)
- Show employee name with department name.
- Show employees working in Engineering department.
- Show employee + department + location.
- Show all employees and their projects (via department).
- Count employees in each department with department name.
- Show employees who belong to Pune location.
- Show employees with no department (LEFT JOIN case).
- Show department with total salary of employees.
- Show highest paid employee in each department.
- Show departments with no employees.
🔵 LEVEL 4 — Salary & History
- Show employees who got increment.
- Show old salary vs new salary.
- Highest increment given to which employee?
- Count total increments.
- Employees whose salary increased >5000.
- Latest increment date.
- Show employee name with increment details.
- Total increment amount company paid.
- Employees who never got increment.
- First employee who got increment.
🟣 LEVEL 5 — Attendance
- Show all absent employees.
- Count present employees.
- Count absent employees.
- Show attendance for employee Swapnil.
- Employees working from home.
- Count attendance per employee.
- Employee with most absences.
- Show attendance with employee name.
- Count attendance per day.
- Employees absent on 2026-02-01.
🔴 LEVEL 6 — Advanced (Interview level)
- 2nd highest salary.
- 3rd highest salary.
- Employees earning above company average.
- Department with highest total salary.
- Employee with highest salary in each department.
- Rank employees by salary.
- Show duplicate salaries.
- Employees who earn more than their manager (assume self compare).
- Running total of salaries.
- Salary difference between highest and lowest.
🏆 SUPER CHALLENGE (Real interview)
- Top 3 salaries per department.
- Department where avg salary > company avg.
- Employees hired in last 2 years.
- Salary ranking within department.
- Department with no projects.
- Project count per department.
- Employees working on same dept as Swapnil.
- Highest salary in Pune location.
- Attendance percentage per employee.
- Create view for employee + dept + salary.