TGViewer
SQL Programming Resources SQL Programming Resources @sqlanalyst ยท 76.7K subscribers
Post #2193 5.92K
โœ… SQL Practice Questions with Answers: Part-2 ๐Ÿง ๐Ÿ—ƒ๏ธ

๐Ÿ” Q7. Find employees who never received a bonus
๐Ÿ‘ค Table: employees
id | name
1 | Arjun
2 | Riya
3 | Meena

๐Ÿ’ฐ Table: bonus
employee_id | bonus_amount
1 | 3000
3 | 5000

๐Ÿ“„ Query:
SELECT e.id, e.name  
FROM employees e
LEFT JOIN bonus b ON e.id = b.employee_id
WHERE b.employee_id IS NULL;

๐Ÿ“Œ Result: Riya

๐Ÿ” Q8. Get highest salary employee from each department
๐Ÿงพ Table: employees
id | name | dept | salary
1 | Arjun | HR | 40000
2 | Riya | IT | 55000
3 | Meena | IT | 62000
4 | Kabir | HR | 45000

๐Ÿ“„ Query:
SELECT e.*  
FROM employees e
JOIN (
SELECT department, MAX(salary) AS max_salary
FROM employees
GROUP BY department
) t
ON e.department = t.department
AND e.salary = t.max_salary;

๐Ÿ“Œ Result: Kabir (HR), Meena (IT)

๐Ÿ” Q9. Count number of employees who joined each year
๐Ÿ—“ Table: employees
id | name | join_date
1 | Arjun | 2021-03-10
2 | Riya | 2022-05-12
3 | Meena | 2021-11-03
4 | Kabir | 2023-01-09

๐Ÿ“„ Query:
SELECT YEAR(join_date) AS join_year, COUNT(*) AS total  
FROM employees
GROUP BY YEAR(join_date)
ORDER BY join_year;

๐Ÿ“Œ Result:
2021 โ†’ 2
2022 โ†’ 1
2023 โ†’ 1

๐Ÿ” Q10. Find employees earning more than department average
๐Ÿงพ Table: employees
id | name | dept | salary
1 | Arjun | HR | 40000
2 | Riya | IT | 55000
3 | Meena | IT | 62000
4 | Kabir | HR | 45000

๐Ÿ“„ Query:
SELECT e.*  
FROM employees e
JOIN (
SELECT department, AVG(salary) AS avg_salary
FROM employees
GROUP BY department
) t
ON e.department = t.department
WHERE e.salary > t.avg_salary;

๐Ÿ“Œ Result: Kabir (HR), Meena (IT)

๐Ÿ” Q11. Fetch the 5th highest salary from employee table
๐Ÿงพ Table: employees
Salaries: 90000, 85000, 78000, 76000, 72000, 70000

๐Ÿ“„ Query:
SELECT DISTINCT salary  
FROM employees
ORDER BY salary DESC
LIMIT 1 OFFSET 4;

๐Ÿ“Œ Result: 72000

๐Ÿ” Q12. Find employees working on more than one project
๐Ÿ“‚ Table: project_assignments
employee_id | project_id
1 | 101
1 | 102
2 | 103
3 | 104
3 | 105
3 | 106

๐Ÿ“„ Query:
SELECT employee_id, COUNT(*) AS project_count  
FROM project_assignments
GROUP BY employee_id
HAVING COUNT(*) > 1;

๐Ÿ“Œ Result:
1 โ†’ 2 projects
3 โ†’ 3 projects

๐Ÿ’ฌ Tap โค๏ธ for more!
  • โค 13
More from @sqlanalyst
  1. Oct 13, 2026SQL Interview Series โ€” Part 8 ๐Ÿ“Œ Question 8: Find Customers Who Have Never Placed an Orderโ€ฆ
  2. Oct 13, 2026๐—ง๐—ข๐—ฃ ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ข๐—จ๐—ฅ๐—ฆ๐—˜๐—ฆ ๐—ง๐—ข ๐—•๐—ข๐—ข๐—ฆ๐—ง ๐—ฌ๐—ข๐—จ๐—ฅ ๐—ฆ๐—ž๐—œ๐—Ÿ๐—Ÿ๐—ฆ ๐—œ๐—ก ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ! Explorโ€ฆ
  3. Oct 12, 2026SQL Interview Series โ€” Part 6 ๐Ÿ“Œ Question 6: Find the Top 2 Highest-Paid Employees in Eachโ€ฆ
  4. Oct 12, 2026๐Ÿš€ ๐—ช๐—ต๐—ถ๐—ฐ๐—ต ๐—ง๐—ฒ๐—ฐ๐—ต ๐—ฆ๐—ธ๐—ถ๐—น๐—น ๐—ช๐—ถ๐—น๐—น ๐—ฌ๐—ผ๐˜‚ ๐— ๐—ฎ๐˜€๐˜๐—ฒ๐—ฟ ๐—ถ๐—ป ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ? Want to builโ€ฆ
  5. Oct 9, 2026SQL Interview Series โ€” Part 5 ๐Ÿ“Œ Question 5: Find Employees Who Earn More Than Their Managโ€ฆ
  6. Oct 9, 2026๐Ÿ‡ฎ๐Ÿ‡ณ ๐—š๐—ข๐—ฉ๐—˜๐—ฅ๐—ก๐— ๐—˜๐—ก๐—ง ๐—ข๐—™ ๐—œ๐—ก๐——๐—œ๐—” โ€” ๐—”๐—œ๐—–๐—ง๐—˜ ๐—œ๐—ก๐—ง๐—˜๐—ฅ๐—ก๐—ฆ๐—›๐—œ๐—ฃ๐—ฆ ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ ๐Ÿš€โ€ฆ
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook โ†’Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 โ†’