Skip to main content

SQL Practice Questions and Interview Examples

SQL Practice and Interview Questions | Sabbir93s Blog

SQL Practice Questions and Interview Examples

This guide provides hands-on SQL exercises and interview-style questions using real-world dataset formats. Perfect for students, job seekers, and data enthusiasts.


Sample Dataset: Employees Table


+----+--------+-----------+------------+---------+
| ID | Name   | Dept      | Salary     | Joining |
+----+--------+-----------+------------+---------+
| 1  | Alice  | HR        | 50000      | 2019-05 |
| 2  | Bob    | IT        | 75000      | 2020-01 |
| 3  | Carol  | Finance   | 68000      | 2018-09 |
| 4  | Dave   | IT        | 80000      | 2021-03 |
| 5  | Eve    | Finance   | 70000      | 2020-07 |
+----+--------+-----------+------------+---------+
    

1. Basic Practice Questions

Q1. Select all employees in the IT department

SELECT * FROM employees WHERE dept = 'IT';

Q2. Find total salary paid to the Finance department

SELECT SUM(salary) FROM employees WHERE dept = 'Finance';

Q3. Count employees who joined after 2019

SELECT COUNT(*) FROM employees WHERE joining > '2019-12-31';

Q4. List employee names ordered by salary descending

SELECT name FROM employees ORDER BY salary DESC;

Q5. Find average salary by department

SELECT dept, AVG(salary) AS avg_salary FROM employees GROUP BY dept;

2. Intermediate SQL Exercises

Q6. Display the highest-paid employee in each department


SELECT dept, name, salary
FROM employees e
WHERE salary = (
  SELECT MAX(salary)
  FROM employees
  WHERE dept = e.dept
);
    

Q7. Retrieve employees whose name starts with 'A'

SELECT * FROM employees WHERE name LIKE 'A%';

Q8. Add a new employee


INSERT INTO employees (ID, Name, Dept, Salary, Joining)
VALUES (6, 'Frank', 'HR', 55000, '2023-02');
    

Q9. Update salary of Bob by 10%


UPDATE employees
SET salary = salary * 1.10
WHERE name = 'Bob';
    

Q10. Delete employees from the HR department

DELETE FROM employees WHERE dept = 'HR';

3. Interview-Style SQL Questions

Q11. What is the difference between WHERE and HAVING?

WHERE filters rows before grouping; HAVING filters after aggregation.

Q12. Retrieve departments having more than 1 employee


SELECT dept, COUNT(*) AS emp_count
FROM employees
GROUP BY dept
HAVING COUNT(*) > 1;
    

Q13. Write a query to rank employees by salary in each department


SELECT name, dept, salary,
  RANK() OVER (PARTITION BY dept ORDER BY salary DESC) AS rank
FROM employees;
    

Q14. Explain use of JOIN in multi-table queries?

JOIN is used to combine rows from multiple tables based on related columns (e.g., foreign keys).

Q15. What is the purpose of indexing?

Indexes speed up data retrieval by reducing the number of rows scanned.


Also Read:

Final Tips

  • Practice regularly using mock datasets.
  • Use platforms like LeetCode, Hackerrank, or SQLZoo for timed challenges.
  • Understand logic, not just syntax.

For more tutorials, visit Sabbir93s SQL Series.

Comments

Popular posts from this blog

How to Earn from Clipster.gg in 2025

How to Earn from Clipster.gg (2025 Guide) 💸 How to Earn from Clipster.gg in 2025 Clipster.gg is a platform where you can earn money from viral videos using three simple methods: logo promotion , UGC content , and content clipping . Let’s break them down: 🔥 1. Logo Promotion Pick any brand’s logo from the campaign section and simply overlay it on top of your short-form videos (Reels, Shorts, TikTok). Once your videos get views, you get paid based on performance. No need for fancy editing. 🎥 2. UGC Content Creation Create your own reaction, meme, skit or short-form video based on the campaign theme. If your video performs well (goes viral), you earn money based on views. This is perfect for creators who want to make engaging content. 📁 3. Content Clipping (Copy & Paste Method) Clipster provides ready-made clips in Google Drive or folders. You simply download the videos and repost them as Sho...

Beatriz Taufenbach vs Natalie Burn: Real Truth Behind the Viral Toxic Trailer Scene (2026) — Explained

Beatriz Taufenbach vs Natalie Burn: Real Truth Behind the Viral Toxic Trailer Scene (2026) — Explained The teaser for “ Toxic: A Fairy Tale for Grown-Ups ” starring Yash exploded across the internet after its January 2026 release, not just for its gritty action but for one sensuous, viral moment in a cemetery sequence. Almost immediately, fans and content sites were searching terms like “Toxic trailer mystery actress,” “Beatriz Taufenbach identity,” and “Natalie Burn Toxic scene” to understand who the foreign woman in that intimate car sequence really is. What followed was a mix of misinformation, viral curiosity, and eventual clarification straight from the director’s official account. Here’s the complete, true story behind the confusion — what’s factual, what’s rumor, and who the real actress is. The Viral Moment That Sparked the Searches When the Toxic teaser dropped on January 8, 2026 — intentionally released on Yash’s birthday — millions of viewers were captivated by a bold and in...

Mitolyn Supplements – A Revolutionary Formula for Slimming!

Mitolyn Supplements: The Natural Solution for Rapid Weight Loss and Enhanced Metabolism" Mitolyn slimming supplement ingredients” or “natural fat burning supplement. Buy now  In today’s world, staying fit and maintaining a healthy weight is more than just a trend—it’s a necessity. If you're looking for an effective and natural supplement to support your weight loss journey, Mitolyn Supplements might be the perfect solution for you. What is Mitolyn? Mitolyn is an advanced slimming supplement designed to enhance metabolism and promote fat burning. It is specifically formulated for those who want to lose weight naturally and safely. Made with natural ingredients, Mitolyn Supplements support your body’s natural fat-burning mechanisms, ensuring a safe and effective weight loss experience. How Does Mitolyn Work? Boosts Fat Burning Process: Helps activate your body's natural fat-burning mechanism. Speeds Up Metabolism: A faster metabolism means quicker calorie burning, making it ...