SQL Interview Questions for Freshers

Published August 18, 2026 · 6 min read

SQL interview questions for freshers cluster around four things: keys and normalization (the theory), JOIN types (the most-asked topic by far), the difference between a handful of commonly confused clauses, and one query you're expected to actually write on the spot — almost always some variation of "find the Nth highest value."

Keys and Normalization

Primary key vs. foreign key. A primary key uniquely identifies each row in a table and can't be null. A foreign key is a column that references a primary key in another table, enforcing that the relationship between the two tables stays valid.

Normalization, briefly. 1NF requires atomic values (no repeating groups or lists in a single cell). 2NF builds on 1NF by removing partial dependency — every non-key column must depend on the whole primary key, not just part of it. 3NF builds on 2NF by removing transitive dependency — a non-key column shouldn't depend on another non-key column. Most interviewers stop at 3NF; you rarely need to go further for a fresher-level answer.

JOIN Types (the Most-Asked SQL Topic)

INNER JOIN returns only rows that match in both tables. LEFT JOIN returns every row from the left table, plus matched data from the right table where it exists (null where it doesn't). RIGHT JOIN is the mirror of LEFT JOIN. FULL JOIN returns every row from both tables, matched where possible. If you can draw these as Venn diagrams from memory, you'll never fumble this question.

Commonly Confused Clauses

WHERE vs. HAVING. WHERE filters individual rows before grouping happens. HAVING filters groups after a GROUP BY aggregation — which is why you can use an aggregate function like COUNT() in a HAVING clause but not in a WHERE clause.

DELETE vs. TRUNCATE vs. DROP. DELETE removes rows one at a time, can use a WHERE clause, and can typically be rolled back. TRUNCATE removes all rows at once, is faster, and resets any auto-increment counter — but you can't target specific rows with it. DROP removes the entire table structure, not just the data.

A Query You Should Be Able to Write

The classic: find the second-highest salary in an employees table. The portable version that works across most SQL databases:

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

Being able to explain why this works — the inner query finds the highest salary, and the outer query finds the highest salary that's strictly less than that — matters more than having it memorized. Interviewers often follow up by asking for the Nth-highest version, which generalizes the same idea with a subquery and a LIMIT/OFFSET or DENSE_RANK(), depending on what the database supports.

How to Prepare

Write these queries by hand, not just read them — the muscle memory of getting JOIN syntax and subqueries right under time pressure is what actually gets tested. Practice explaining the theory questions out loud with a live-scored AI Mock Interview, or drill one question a day with Flash Practice.

Frequently Asked Questions

What's the difference between a primary key and a foreign key? A primary key uniquely identifies each row in a table and can't be null. A foreign key is a column that references a primary key in another table, enforcing that the relationship between the two tables stays valid.

What's the difference between INNER JOIN, LEFT JOIN, and FULL JOIN? INNER JOIN returns only matching rows in both tables. LEFT JOIN returns every row from the left table plus matches from the right (null where none exist). FULL JOIN returns every row from both tables, matched where possible.

What's the difference between WHERE and HAVING? WHERE filters individual rows before grouping happens. HAVING filters groups after a GROUP BY aggregation, which is why an aggregate function like COUNT() works in HAVING but not in WHERE.

How do you find the second-highest salary in a table? SELECT MAX(salary) FROM employees WHERE salary < (SELECT MAX(salary) FROM employees) — the inner query finds the highest salary, and the outer query finds the highest salary strictly less than that.