SQL Interview Questions for Freshers
The short answer
SQL rounds usually ask about queries and keys. The bank has 10 questions, including WHERE versus HAVING, inner versus left join, primary, unique and foreign keys, normalisation, DELETE versus TRUNCATE versus DROP, and indexes. Each has notes on what to say.
10 questions. Open one to see what a good answer covers.
What is the difference between WHERE and HAVING?
WHERE filters rows before grouping and cannot use aggregate functions. HAVING filters groups after GROUP BY and can use aggregates such as COUNT or SUM.
What is the difference between INNER JOIN and LEFT JOIN?
INNER JOIN returns only rows that match in both tables. LEFT JOIN returns every row of the left table and fills the right table's columns with NULL where there is no match.
What are a primary key, a unique key and a foreign key?
A primary key identifies each row uniquely and cannot be NULL. A unique key also stops duplicates but allows a NULL. A foreign key points to a primary key in another table to link them.
What is normalisation?
Organising tables to reduce repeated data and mistakes. First normal form has single values in each cell, second removes partial dependencies and third removes dependencies between non-key columns.
What is the difference between DELETE, TRUNCATE and DROP?
DELETE removes chosen rows and can be rolled back. TRUNCATE removes all rows quickly and keeps the table. DROP removes the whole table and its structure.
What is an index, and when can it hurt?
An index is a structure that makes searches on a column faster. It speeds up reads but slows inserts and updates and uses space, so index the columns you filter and join on, not everything.
What are the ACID properties?
Atomicity (all or nothing), Consistency (rules always hold), Isolation (transactions do not disturb each other) and Durability (committed data survives a crash). They keep transactions reliable.
How would you find the second highest salary?
One way is to select the maximum salary below the overall maximum, using a subquery. Another is to use DENSE_RANK or LIMIT with OFFSET. Mention duplicates and what you want when two people share a salary.
What is the difference between a subquery and a join?
A subquery is a query inside another, a join combines tables side by side. Joins are often faster and clearer, while subqueries can be easier to read for simple filters.
What is a view?
A saved query that behaves like a virtual table. It hides complexity, can restrict what users see and does not store data itself, unless it is a materialised view.
Everything runs in your browser. What you type is not sent anywhere.
How to: SQL Interview Questions for Freshers
- 1Read the question and write a sample query on paper.
- 2Open the tip and check the points you missed.
- 3Say the difference aloud as if to a colleague.
- 4Practise again with the timer.
At a glance
- Questions
- 10 SQL and database questions
- Includes
- Joins, keys, normalisation, indexes
- Time to aim for
- About 60 seconds each
Frequently asked questions
What is the easiest way to explain a join?
Say that a join combines rows from two tables on a matching column. An inner join keeps only matches, and a left join also keeps unmatched rows from the left table.
Will I be asked to write queries?
Very often. Practise on a small sample table with a few students and marks, and be ready to explain your result row by row.
More quick answers
- HR Interview Questions for Freshers: Tell Me About Yourself
- Behavioural Interview Questions and the STAR Method
- Python Interview Questions for Freshers
- Java Interview Questions for Freshers
- Data Structures and Algorithms Interview Questions for Freshers
- Web Development Interview Questions for Freshers
- CS Fundamentals Interview Questions: OOP, OS and Networks
- Excel and Data Analysis Interview Questions for Freshers