Free tutorials in Hindi & English Daily computer, mobile and IT guides Beginner friendly learning
Blog · MySQL / SQL · 04 Jul 2026 · Hindi + English

Top 15 SQL Interview Questions for Freshers with Answers

15 most-asked SQL questions with ready answers: keys, joins, WHERE vs HAVING, DELETE vs TRUNCATE, normalization, second-highest salary query and more.

How to use this list

These 15 questions dominate SQL rounds for freshers — a mix of concept questions and the write-a-query classics. Answers are worded the way you should speak them.

Concepts (1–8)

Q1. What is the difference between SQL and MySQL?

SQL is the language (the grammar for querying data); MySQL is a database software that understands that language. Like English vs a person who speaks English — others (PostgreSQL, Oracle, SQL Server) speak it too, with small accents.

Q2. Primary key vs foreign key?

Primary key uniquely identifies rows in its own table (no duplicates, no NULL); foreign key stores those values in another table to link them, enforcing referential integrity — a fee row cannot reference a student who doesn't exist.

Q3. DELETE vs TRUNCATE vs DROP?

DELETE removes chosen rows (WHERE, rollback possible, DML); TRUNCATE empties the table fast (no WHERE, auto-commits, resets AUTO_INCREMENT, DDL); DROP removes the table itself with its structure.

Q4. WHERE vs HAVING?

WHERE filters rows before grouping and cannot use aggregates; HAVING filters groups after GROUP BY and exists for aggregate conditions like HAVING AVG(marks) > 70.

Q5. Types of JOINs?

INNER (matches only), LEFT (all left + matches, NULL where missing), RIGHT (all right + matches), FULL (both sides — MySQL lacks the keyword, simulate with LEFT UNION RIGHT).

Q6. UNION vs UNION ALL?

UNION merges and removes duplicates (slower); UNION ALL keeps everything (faster). Prefer UNION ALL when overlap is impossible.

Q7. What is normalization?

Organizing tables so each fact lives once, removing update/insert/delete anomalies. The trick line: "the key (1NF), the whole key (2NF), nothing but the key (3NF)."

Q8. What is an index and its cost?

A sorted B-tree lookup that makes searched columns fast (book-index style), at the cost of slower writes (every change maintains the index) and extra storage.

The write-a-query classics (9–15)

Q9. Find the second highest salary (THE most asked SQL question)

SELECT MAX(salary) FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);

-- or the LIMIT way:
SELECT DISTINCT salary FROM employees
ORDER BY salary DESC LIMIT 1 OFFSET 1;

Q10. Find duplicate emails

SELECT email, COUNT(*) FROM users
GROUP BY email HAVING COUNT(*) > 1;

Q11. Students with no marks entry (LEFT JOIN + NULL)

SELECT s.name FROM students s
LEFT JOIN marks m ON s.roll_no = m.roll_no
WHERE m.roll_no IS NULL;

Q12. Count students per class, only classes with 30+

SELECT class, COUNT(*) AS total FROM students
GROUP BY class HAVING COUNT(*) >= 30;

Q13. Top 3 scorers

SELECT name, marks FROM students
ORDER BY marks DESC LIMIT 3;

Q14. Why does WHERE marks = NULL return nothing?

NULL is "unknown" — nothing equals unknown, not even another NULL. Use IS NULL / IS NOT NULL. This one-word fix is a guaranteed question.

Q15. What is the SQL execution order?

FROM → WHERE → GROUP BY → HAVING → SELECT → ORDER BY → LIMIT. Knowing this order explains why WHERE can't use aggregates and why column aliases don't work in WHERE.

Last-minute revision line

If you master only 5 things: second-highest-salary query, LEFT JOIN + IS NULL pattern, GROUP BY + HAVING COUNT for duplicates, the execution order, and DELETE/TRUNCATE/DROP differences — you can handle the majority of fresher SQL rounds.

इस list को कैसे use करें

Freshers के SQL rounds में यही 15 questions छाए रहते हैं — concept questions और write-a-query classics का mix. Answers वैसे लिखे हैं जैसे बोलने चाहिए.

Concepts (1–8)

Q1. SQL और MySQL में अंतर?

SQL language है (data query करने की grammar); MySQL एक database software है जो वह language समझता है. जैसे English vs English बोलने वाला इंसान — दूसरे (PostgreSQL, Oracle, SQL Server) भी बोलते हैं, थोड़े अलग accent से.

Q2. Primary key vs foreign key?

Primary key अपनी table की rows को uniquely पहचानती है (न duplicates, न NULL); foreign key वही values दूसरी table में store करके उन्हें जोड़ती है, referential integrity enforce करते हुए — fee row ऐसे student को reference नहीं कर सकती जो है ही नहीं.

Q3. DELETE vs TRUNCATE vs DROP?

DELETE चुनी rows हटाता है (WHERE, rollback possible, DML); TRUNCATE table तेज़ी से खाली करता है (WHERE नहीं, auto-commit, AUTO_INCREMENT reset, DDL); DROP table को structure समेत हटाता है.

Q4. WHERE vs HAVING?

WHERE grouping से पहले rows filter करता है और aggregates use नहीं कर सकता; HAVING GROUP BY के बाद groups filter करता है और HAVING AVG(marks) > 70 जैसी aggregate conditions के लिए ही है.

Q5. JOINs के types?

INNER (सिर्फ matches), LEFT (सारा left + matches, missing पर NULL), RIGHT (सारा right + matches), FULL (दोनों तरफ — MySQL में keyword नहीं, LEFT UNION RIGHT से simulate).

Q6. UNION vs UNION ALL?

UNION मिलाकर duplicates हटाता है (धीमा); UNION ALL सब रखता है (तेज़). Overlap impossible हो तो UNION ALL prefer करें.

Q7. Normalization क्या है?

Tables को ऐसे organize करना कि हर fact एक जगह रहे, update/insert/delete anomalies हटें. Trick line: "the key (1NF), the whole key (2NF), nothing but the key (3NF)."

Q8. Index क्या है और उसकी कीमत?

Sorted B-tree lookup जो searched columns को तेज़ करता है (किताब के index जैसा), बदले में धीमे writes (हर change पर index maintain) और extra storage.

Write-a-query classics (9–15)

Q9. Second highest salary निकालें (SQL का सबसे ज़्यादा पूछा question)

SELECT MAX(salary) FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);

-- या LIMIT वाला तरीका:
SELECT DISTINCT salary FROM employees
ORDER BY salary DESC LIMIT 1 OFFSET 1;

Q10. Duplicate emails ढूंढें

SELECT email, COUNT(*) FROM users
GROUP BY email HAVING COUNT(*) > 1;

Q11. जिन students की marks entry नहीं (LEFT JOIN + NULL)

SELECT s.name FROM students s
LEFT JOIN marks m ON s.roll_no = m.roll_no
WHERE m.roll_no IS NULL;

Q12. हर class के students गिनें, सिर्फ 30+ वाली classes

SELECT class, COUNT(*) AS total FROM students
GROUP BY class HAVING COUNT(*) >= 30;

Q13. Top 3 scorers

SELECT name, marks FROM students
ORDER BY marks DESC LIMIT 3;

Q14. WHERE marks = NULL कुछ क्यों नहीं देता?

NULL "unknown" है — unknown के बराबर कुछ नहीं होता, दूसरा NULL भी नहीं. IS NULL / IS NOT NULL use करें. यह one-word fix guaranteed question है.

Q15. SQL का execution order क्या है?

FROM → WHERE → GROUP BY → HAVING → SELECT → ORDER BY → LIMIT. यह order पता हो तो समझ आता है WHERE aggregates क्यों नहीं ले सकता और column aliases WHERE में क्यों नहीं चलते.

Last-minute revision line

सिर्फ 5 चीज़ें master करनी हों: second-highest-salary query, LEFT JOIN + IS NULL pattern, duplicates के लिए GROUP BY + HAVING COUNT, execution order, और DELETE/TRUNCATE/DROP के अंतर — freshers के अधिकतर SQL rounds संभल जाएंगे.

Frequently Asked Questions

What is the most asked SQL interview question?

Finding the second highest salary — solvable with MAX(salary) below the overall MAX in a subquery, or with ORDER BY salary DESC LIMIT 1 OFFSET 1 on distinct salaries.

Why does WHERE column = NULL not work?

NULL means unknown, and no value equals unknown — comparisons with = always fail against NULL; the correct operators are IS NULL and IS NOT NULL.

What is the SQL query execution order?

FROM, then WHERE, then GROUP BY, then HAVING, then SELECT, then ORDER BY, then LIMIT — which is why WHERE cannot use aggregates or SELECT aliases.