Top 50 SQL Interview Questions — Crack Your Next Interview
Basic SQL Questions (1-10)
1. What is the difference between WHERE and HAVING?
WHERE filters rows before GROUP BY. HAVING filters groups after GROUP BY.
SELECT city, COUNT(*) FROM students WHERE age > 18 GROUP BY city HAVING COUNT(*) > 5;
2. What is a PRIMARY KEY?
A column that uniquely identifies each row. Cannot be NULL or duplicate.
3. What is the difference between DELETE and TRUNCATE?
DELETE: Can use WHERE, logged, can rollback. TRUNCATE: Removes all rows, faster, cannot rollback.
Intermediate SQL Questions (11-30)
11. What is a SELF JOIN?
A table joined with itself. Used when comparing rows in the same table.
SELECT e.name, m.name FROM employees e JOIN employees m ON e.manager_id = m.id;
15. What are Window Functions?
Functions that perform calculations across rows related to the current row. Examples: ROW_NUMBER(), RANK(), SUM() OVER().
Advanced SQL Questions (31-50)
35. What is query optimization?
Techniques to make SQL queries faster: indexing, avoiding SELECT *, using EXPLAIN, partitioning, query rewriting.
Practice SQL with DSWallah
DSWallah's SQL course covers all these concepts with 200+ practice problems and interview preparation.
WhatsApp for SQL Course Details →Ready to Start Your Data Science Journey?
Join 300+ students who transformed their careers with DSWallah. IIT-certified mentor, 50+ real projects, placement support.
WhatsApp for Free Demo →