TGViewer
SQL Programming Resources SQL Programming Resources @sqlanalyst · 76.7K subscribers
Post #2308 3.12K
✅ SQL Subquery Practice Questions with Answers

🔎 Q1. Retrieve employees whose salary is greater than the company’s average salary.
🗂️ Table: employees(emp_id, name, salary)

✅ Answer:
SELECT emp_id, name, salary
FROM employees
WHERE salary > (SELECT AVG(salary) FROM employees);


---

🔎 Q2. Identify customers who have placed more than three orders.
🗂️ Table: orders(order_id, customer_id, order_date)

✅ Answer:
SELECT customer_id
FROM orders
WHERE customer_id IN (
SELECT customer_id
FROM orders
GROUP BY customer_id
HAVING COUNT(order_id) > 3
);


---

🔎 Q3. Display employees working in departments where the average salary exceeds 60,000.
🗂️ Table: employees(emp_id, name, department_id, salary)

✅ Answer:
SELECT emp_id, name, department_id
FROM employees e
WHERE department_id IN (
SELECT department_id
FROM employees
GROUP BY department_id
HAVING AVG(salary) > 60000
);


---

🔎 Q4. Show products that have never been ordered.
🗂️ Tables: products(product_id, product_name), orders(order_id, product_id)

✅ Answer:
SELECT product_id, product_name
FROM products
WHERE product_id NOT IN (SELECT product_id FROM orders);


(Alternative safe approach to handle NULLs in orders)
SELECT p.product_id, p.product_name
FROM products p
LEFT JOIN orders o ON p.product_id = o.product_id
WHERE o.product_id IS NULL;


---

🔎 Q5. Fetch employee(s) receiving the maximum salary in the organization.
🗂️ Table: employees(emp_id, name, salary)

✅ Answer:
SELECT emp_id, name, salary
FROM employees
WHERE salary = (SELECT MAX(salary) FROM employees);


Double Tap ♥️ For More
  • ❤ 11
More from @sqlanalyst
  1. Oct 12, 2026SQL Interview Series — Part 6 📌 Question 6: Find the Top 2 Highest-Paid Employees in Each…
  2. Oct 12, 2026🚀 𝗪𝗵𝗶𝗰𝗵 𝗧𝗲𝗰𝗵 𝗦𝗸𝗶𝗹𝗹 𝗪𝗶𝗹𝗹 𝗬𝗼𝘂 𝗠𝗮𝘀𝘁𝗲𝗿 𝗶𝗻 𝟮𝟬𝟮𝟲? Want to buil…
  3. Oct 9, 2026SQL Interview Series — Part 5 📌 Question 5: Find Employees Who Earn More Than Their Manag…
  4. Oct 9, 2026🇮🇳 𝗚𝗢𝗩𝗘𝗥𝗡𝗠𝗘𝗡𝗧 𝗢𝗙 𝗜𝗡𝗗𝗜𝗔 — 𝗔𝗜𝗖𝗧𝗘 𝗜𝗡𝗧𝗘𝗥𝗡𝗦𝗛𝗜𝗣𝗦 𝟮𝟬𝟮𝟲 🚀…
  5. Oct 8, 2026🎓 𝗠𝗶𝗰𝗿𝗼𝘀𝗼𝗳𝘁 𝗙𝗥𝗘𝗘 𝗖𝗼𝘂𝗿𝘀𝗲𝘀 𝘄𝗶𝘁𝗵 𝗖𝗲𝗿𝘁𝗶𝗳𝗶𝗰𝗮𝘁𝗲𝘀! 🚀🔥 Upgr…
  6. Oct 7, 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 →