SQL Interview Questions for Freshers, With Short Answers
By the Codveri team ·
The SQL questions freshers are asked most often (joins, GROUP BY, keys, indexes and window functions) with clear answers and a practice routine.
Start with the basics they always ask
What is the difference between WHERE and HAVING? WHERE filters rows before grouping; HAVING filters groups after aggregation. What is the difference between a primary key and a unique key? A table has one primary key and it cannot be NULL; it can have several unique keys.
Be ready to write SELECT with ORDER BY and LIMIT, COUNT versus COUNT(column), and DISTINCT from memory.
Joins, the favourite topic
INNER JOIN returns rows that match in both tables. LEFT JOIN returns every row from the left table and fills unmatched right-side columns with NULL. Practise finding customers with no orders: a LEFT JOIN with a WHERE on the right key being NULL.
Draw two small tables on paper and write the result of each join by hand until it feels automatic.
Aggregation and subqueries
Group rows with GROUP BY and filter groups with HAVING. A typical question is the second highest salary: use a subquery, or LIMIT with OFFSET, or a window function such as DENSE_RANK.
Know when a subquery can be rewritten as a join and which is easier to read.
Indexes and normalisation
An index speeds up reads on a column by keeping it sorted in a structure such as a B-tree, but it slows writes and uses space. Normalisation removes duplicated data by splitting tables, while denormalisation trades that for faster reads.
Be able to explain first, second and third normal form in one sentence each.
Transactions and ACID
A transaction groups statements so they succeed or fail together. ACID stands for atomicity, consistency, isolation and durability. Be ready with the example of transferring money between two accounts.
How to practise
Take a free sample database, write ten queries a day for a week, and then take a timed Databases test on Codveri to find your gaps.