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

๐Ÿ” Q13. Find employees whose salary is above the company average
๐Ÿงพ Table: employees
id | name | salary
1 | Arjun | 40000
2 | Riya | 55000
3 | Meena | 62000
4 | Kabir | 45000

๐Ÿ“„ Query:
SELECT *  
FROM employees
WHERE salary > (SELECT AVG(salary) FROM employees);

๐Ÿ“Œ Result: Riya, Meena

๐Ÿ” Q14. Get the 3 most recent joined employees
๐Ÿ—“ Table: employees
id | name | join_date
1 | Arjun | 2021-03-10
2 | Riya | 2022-05-12
3 | Meena | 2023-02-01
4 | Kabir | 2023-11-09

๐Ÿ“„ Query:
SELECT *  
FROM employees
ORDER BY join_date DESC
LIMIT 3;

๐Ÿ“Œ Result: Kabir, Meena, Riya

๐Ÿ” Q15. Retrieve employees who donโ€™t have a manager assigned
๐Ÿงพ Table: employees
id | name | manager_id
1 | Arjun | NULL
2 | Riya | 1
3 | Meena | NULL
4 | Kabir | 2

๐Ÿ“„ Query:
SELECT id, name  
FROM employees
WHERE manager_id IS NULL;

๐Ÿ“Œ Result: Arjun, Meena

๐Ÿ” Q16. Find departments where more than 2 employees work
๐Ÿงพ Table: employees
id | name | department
1 | Arjun | HR
2 | Riya | IT
3 | Meena | IT
4 | Kabir | HR
5 | John | IT

๐Ÿ“„ Query:
SELECT department, COUNT(*) AS total  
FROM employees
GROUP BY department
HAVING COUNT(*) > 2;

๐Ÿ“Œ Result: IT โ†’ 3 employees

๐Ÿ” Q17. Select employees whose salary equals 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 dept, AVG(salary) AS avg_salary
FROM employees
GROUP BY dept
) t ON e.dept = t.dept
WHERE e.salary = t.avg_salary;

๐Ÿ“Œ Result: None (but logic works if matches exist)

๐Ÿ” Q18. Get employees who have at least one matching project
๐Ÿ“‚ Table: project_assignments
employee_id | project_id
1 | 101
2 | 101
2 | 102
3 | 103
4 | 101

๐Ÿ“„ Query:
SELECT p1.employee_id, p2.employee_id AS colleague  
FROM project_assignments p1
JOIN project_assignments p2
ON p1.project_id = p2.project_id
AND p1.employee_id <> p2.employee_id;

๐Ÿ“Œ Result:
Employees 1, 2, 4 share project 101

๐Ÿ’ฌ Tap โค๏ธ for more!
  • โค 18
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 โ†’