SQL Interview Questions for Freshers (2026): 35 Questions with Answers
- Home
- Blog
- Full Stack & Programming
- SQL Interview Questions for Freshers (2026): 35 Questions with Answers
Short answer: SQL interviews for freshers test four things: the core query clauses (SELECT, WHERE, GROUP BY, HAVING, ORDER BY), the joins (INNER, LEFT, RIGHT, FULL), database design (primary and foreign keys, normalization) and a few deeper topics (subqueries, indexes, transactions and ACID). Almost every interview also asks you to write a query or two, such as the second-highest salary or the number of orders per customer. The answers and queries below are the ones that come up most.
This guide is for developers and all freshers. If you are targeting analyst roles, also read our SQL interview questions for data analysts, which go deeper into window functions and business queries, and top SQL skills every beginner needs.
SQL basics
1. What is SQL?
Structured Query Language, the standard language for working with relational databases: defining tables, and inserting, querying, updating and deleting data.
2. What are the sub-languages of SQL?
| Group | Purpose | Commands |
|---|---|---|
| DDL | Define structure | CREATE, ALTER, DROP, TRUNCATE |
| DML | Change data | INSERT, UPDATE, DELETE |
| DQL | Query data | SELECT |
| DCL | Permissions | GRANT, REVOKE |
| TCL | Transactions | COMMIT, ROLLBACK, SAVEPOINT |
3. What is the difference between DELETE, TRUNCATE and DROP?
DELETE removes rows (optionally with a WHERE) and can be rolled back. TRUNCATE removes all rows quickly and cannot be filtered. DROP removes the whole table, including its structure.
4. What is the difference between WHERE and HAVING?
WHERE filters rows before grouping; HAVING filters groups after GROUP BY. You use HAVING with aggregate conditions such as HAVING COUNT(*) > 5.
5. What is the logical order of a SELECT query?
FROM and JOIN, then WHERE, then GROUP BY, then HAVING, then SELECT, then ORDER BY, then LIMIT. This is why you cannot use a SELECT alias in WHERE, but can in ORDER BY.
6. What is the difference between CHAR and VARCHAR?
CHAR(n) is fixed length and padded; VARCHAR(n) stores only the characters used, up to n. Use VARCHAR for most text.
Keys and constraints
7. What is a primary key?
A column (or set of columns) that uniquely identifies each row. It cannot be null and must be unique. A table has one primary key.
8. What is a foreign key?
A column that references the primary key of another table, enforcing a valid relationship between the two (referential integrity).
9. What is the difference between a primary key and a unique key?
Both enforce uniqueness, but a table can have only one primary key (never null), while it can have several unique keys, and a unique column can usually hold one null.
10. What are constraints?
Rules on columns: NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK and DEFAULT. They keep data valid at the database level.
Joins
11. What is a join?
A way to combine rows from two or more tables based on a related column, usually a foreign key matching a primary key.
12. Explain the types of joins.
| Join | Returns |
|---|---|
| INNER JOIN | Only rows with a match in both tables |
| LEFT JOIN | All rows from the left table, plus matches (NULLs where none) |
| RIGHT JOIN | All rows from the right table, plus matches |
| FULL OUTER JOIN | All rows from both, matched where possible |
| CROSS JOIN | Every combination of rows (Cartesian product) |
| SELF JOIN | A table joined to itself, e.g. employee to manager |
SELECT c.name, o.id
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.id;
13. How do you find rows with no match (for example customers with no orders)?
SELECT c.name
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.id
WHERE o.id IS NULL;
14. What is the difference between UNION and UNION ALL?
UNION combines two result sets and removes duplicates; UNION ALL keeps duplicates and is faster. Both need matching columns and types.
Aggregates and grouping
15. What are aggregate functions?
COUNT, SUM, AVG, MIN and MAX. They summarise many rows into one value, usually per group with GROUP BY.
16. Count orders per customer.
SELECT customer_id, COUNT(*) AS order_count
FROM orders
GROUP BY customer_id
ORDER BY order_count DESC;
17. What is the difference between COUNT(*), COUNT(column) and COUNT(DISTINCT column)?
COUNT(*) counts all rows; COUNT(column) counts non-null values; COUNT(DISTINCT column) counts unique non-null values.
18. How do NULLs behave in SQL?
NULL means “unknown”. Comparisons with it return unknown, so you must use IS NULL / IS NOT NULL, and most aggregates ignore NULLs. Use COALESCE(col, 0) to substitute a value.
Subqueries and views
19. What is a subquery?
A query nested inside another. It can appear in SELECT, FROM or WHERE, for example filtering on a value computed by an inner query.
20. What is the difference between a correlated and a non-correlated subquery?
A non-correlated subquery runs once on its own. A correlated subquery references the outer query and runs per outer row, which can be slower.
21. What is a view?
A saved SELECT query you can treat like a virtual table. It simplifies complex queries and can restrict which columns users see.
22. What is a stored procedure?
A saved block of SQL (and logic) you can call by name, with parameters. It is used for reusable, server-side operations.
Database design
23. What is normalization?
Organising tables to reduce redundancy and avoid update anomalies by splitting data into related tables. Common forms are 1NF (atomic values), 2NF (no partial dependency on part of a composite key) and 3NF (no non-key depending on another non-key).
24. What is denormalization and why use it?
Deliberately adding redundancy (for example duplicating a column) to make reads faster, often in reporting or analytics, at the cost of more complex writes.
25. What is a composite key?
A primary key made of two or more columns, used when no single column is unique on its own.
Indexes and performance
26. What is an index?
A data structure that speeds up lookups and sorting on one or more columns, like the index of a book. It makes reads faster but slows writes slightly and uses storage.
27. What is the difference between a clustered and a non-clustered index?
A clustered index determines the physical order of rows, so a table has at most one. Non-clustered indexes are separate structures that point to the rows, and a table can have several.
28. When does an index not help?
On very small tables, on columns with few distinct values, or when a query wraps the column in a function or uses a leading wildcard (LIKE '%abc'), which prevents the index from being used.
29. How would you find why a query is slow?
Read the execution plan (for example EXPLAIN), check for full table scans, add or adjust indexes, avoid SELECT *, and filter early. Make sure join columns are indexed.
Transactions
30. What is a transaction?
A group of statements that succeed or fail as one unit. You COMMIT to save or ROLLBACK to undo, which keeps related changes consistent (for example debiting one account and crediting another).
31. What are the ACID properties?
Atomicity (all or nothing), Consistency (valid state to valid state), Isolation (concurrent transactions do not corrupt each other) and Durability (committed data survives a crash).
32. What is a deadlock?
Two transactions each waiting for a lock the other holds, so neither proceeds. Databases detect this and roll one back; you reduce it by accessing tables in a consistent order and keeping transactions short.
Coding tasks
33. Find the second-highest salary.
SELECT MAX(salary) AS second_highest
FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);
34. Find duplicate emails.
SELECT email, COUNT(*) AS c
FROM users
GROUP BY email
HAVING COUNT(*) > 1;
35. Get the top 3 products by total sales.
SELECT product_id, SUM(amount) AS total
FROM sales
GROUP BY product_id
ORDER BY total DESC
LIMIT 3;
How to prepare
- Create a small practice database (customers, orders, products) and write every query above yourself.
- Drill joins and GROUP BY until they are automatic; they appear in almost every interview.
- Practise explaining normalization, indexes and ACID with one example each.
- For analyst roles, add window functions and business queries from our SQL interview questions for data analysts.
See the full process in our tech interview preparation guide.
Learn SQL at TryCatch Classes
TryCatch Classes’ MySQL Training covers creating databases and tables, CRUD and the WHERE clause, string and aggregate functions, keys and constraints, joins, subqueries, stored procedures, indexes and real reporting queries, with live projects. SQL is also part of the complete Data Analytics Training. Learn at our Borivali West classroom or live online, with a 100% placement guarantee.
A note from Mehul Prajapati, Founder, TryCatch Classes
I have spent 18+ years in IT and training and have personally mentored 12,000+ students. If you are planning your next step in SQL and databases and want a second opinion on your learning path, I am happy to help.
“The technology you learn today may change tomorrow, but your ability to learn will always be your biggest strength. Stay curious, keep upgrading yourself, and never stop growing.”
Message me on WhatsApp at +91 99301 12627 and tell me which blog you read. I would love to hear from you.
Still learning the basics? Read SQL for beginners first.
Frequently asked questions
Is SQL important for freshers in 2026?
Very. SQL appears in developer, data analyst, QA and support roles, because almost every application stores data in a relational database. It is one of the highest-value skills a fresher can show.
MySQL, PostgreSQL or SQL Server for interviews?
The core SQL is the same across them. Learn one well (MySQL is common in India) and you can adapt; interviewers care about joins, grouping and design more than vendor syntax.
How much SQL do developers need vs analysts?
Developers focus on design, joins, transactions and writing efficient queries from an app. Analysts add window functions and heavier aggregation. The fundamentals here apply to both.
Do I need to memorise syntax?
Know the common clauses and joins by heart, since you will write queries on a whiteboard or screen. Rare functions can be looked up on the job.
Cover image: photo by Caspar Camille Rubin on Unsplash.
Keep reading
Full Stack & ProgrammingPython Developer Roadmap for Freshers (2026): Basics to a Job-Ready PathA step-by-step Python developer roadmap for freshers: the basics, functions and data structures, OOP, files and errors, the package ecosystem, then choosing a direction (web, data/AI…Full Stack & ProgrammingJava Developer Roadmap for Freshers (2026): Core Java to Spring BootFull Stack & ProgrammingGit and GitHub for Beginners (2026): Commands, Workflow and First Steps← Previous articleJavaScript Interview Questions for Freshers (2026): 35 Questions with AnswersNext article →Email Marketing for Beginners (2026): A Step-by-Step Guide
