
If you’re walking into a tech interview this year with zero to one year of experience, here’s something you should know: SQL is still one of the most tested skills in 2026 — and most freshers get it wrong not because they don’t know the theory, but because they’ve never thought about how to explain it clearly.
I’ve spoken with hiring managers at mid-size product companies and large MNCs, and the feedback is almost always the same — “they mugged up definitions but couldn’t write a simple JOIN when we asked.”
This guide is different. We’re not going to list 100 questions with copy-paste answers. Instead, we’ll cover the questions that actually come up, explain why interviewers ask them, and show you how to answer in a way that sounds like a developer — not a textbook.
Table of Contents
- Why SQL Still Matters for Freshers in 2026
- Basic SQL Questions You Must Know
- SQL Constraints and Keys
- JOINs — The Section That Makes or Breaks Your Interview
- Aggregate Functions and GROUP BY
- Subqueries and Nested SELECTs
- Indexes, Views, and Stored Procedures
- Commonly Tested SQL Queries (Write These Live)
- Tips to Clear the SQL Round in 2026
- FAQs
Why SQL Still Matters for Freshers in 2026
People keep saying “NoSQL is taking over” — and while that’s partially true for certain domains, relational databases power the majority of business applications today. MySQL, PostgreSQL, and Microsoft SQL Server aren’t going anywhere.
More importantly, roles like Business Analyst, Data Analyst, Backend Developer, QA Engineer, and even some Product Manager positions now include an SQL round. If you’re a fresher applying to any data-adjacent or backend role, you willbe tested on SQL.
The good news? The questions follow predictable patterns. Let’s get into them.
Basic SQL Questions You Must Know
1. What is SQL, and what are its sublanguages?
SQL (Structured Query Language) is the standard language used to interact with relational databases — basically, it lets you store, retrieve, update, and delete data in a structured way.
Its sublanguages divide the types of operations you can perform:
- DDL (Data Definition Language): Deals with structure —
CREATE,ALTER,DROP,TRUNCATE - DML (Data Manipulation Language): Deals with data —
SELECT,INSERT,UPDATE,DELETE - DCL (Data Control Language): Manages permissions —
GRANT,REVOKE - TCL (Transaction Control Language): Manages transactions —
COMMIT,ROLLBACK,SAVEPOINT
Why interviewers ask this: They want to know if you understand that SQL isn’t just “SELECT * FROM table” — it’s a layered language with specific roles for each command.
2. What is the difference between DELETE, TRUNCATE, and DROP?
This is one of the most common fresher questions. Here’s a clean way to remember it:
| Command | What It Does | Can Be Rolled Back? | Uses WHERE Clause? | Affects Structure? |
|---|---|---|---|---|
| DELETE | Removes specific rows | ✅ Yes | ✅ Yes | ❌ No |
| TRUNCATE | Removes all rows | ❌ No (usually) | ❌ No | ❌ No |
| DROP | Deletes the entire table | ❌ No | ❌ No | ✅ Yes |
How to explain it in an interview: “DELETE is like erasing specific entries in a notebook. TRUNCATE tears out all the pages but keeps the notebook. DROP throws the whole notebook in the bin.”
3. What is the difference between WHERE and HAVING?
WHEREfilters rows before groupingHAVINGfilters groups afterGROUP BYhas been applied
sql
-- WHERE filters individual rows
SELECT * FROM orders WHERE amount > 500;
-- HAVING filters groups
SELECT customer_id, SUM(amount)
FROM orders
GROUP BY customer_id
HAVING SUM(amount) > 5000;
SQL Constraints and Keys
4. What is a Primary Key? How is it different from a Unique Key?
A Primary Key uniquely identifies each record in a table. It cannot be NULL, and a table can have only one primary key.
A Unique Key also enforces uniqueness, but it allows one NULL value and a table can have multiple unique keys.
Think of it this way — your employee ID is a primary key (there can only be one you in the system), while your work email might be a unique key (it must be unique, but it’s not the main identifier).
5. What is a Foreign Key?
A Foreign Key is a column (or group of columns) in one table that references the Primary Key in another table. It’s how relational databases establish relationships between tables.
sql
CREATE TABLE orders (
order_id INT PRIMARY KEY,
customer_id INT,
FOREIGN KEY (customer_id) REFERENCES customers(customer_id)
);
It enforces referential integrity — you can’t add an order for a customer that doesn’t exist.
6. What are all the SQL constraints?
NOT NULL— Column cannot store NULL valuesUNIQUE— All values in the column must be differentPRIMARY KEY— Combination of NOT NULL + UNIQUE, one per tableFOREIGN KEY— Links to a primary key in another tableCHECK— Ensures values meet a specific conditionDEFAULT— Sets a default value if none is provided
JOINs — The Section That Makes or Breaks Your Interview
This is where most freshers stumble. Interviewers don’t just want definitions — they want you to write JOINs on a whiteboard or online editor.
7. Explain all types of JOINs with examples
Assume two tables: employees and departments.
INNER JOIN — Returns only rows where there’s a match in both tables.
sql
SELECT e.name, d.dept_name
FROM employees e
INNER JOIN departments d ON e.dept_id = d.dept_id;
LEFT JOIN (LEFT OUTER JOIN) — Returns all rows from the left table, and matched rows from the right. Unmatched right-side values are NULL.
sql
SELECT e.name, d.dept_name
FROM employees e
LEFT JOIN departments d ON e.dept_id = d.dept_id;
RIGHT JOIN — The reverse of LEFT JOIN. All rows from the right table, matched from the left.
FULL OUTER JOIN — Returns all rows from both tables. Unmatched rows get NULLs on the missing side.
SELF JOIN — A table joined to itself. Useful for hierarchical data like manager-employee relationships.
sql
SELECT e1.name AS Employee, e2.name AS Manager
FROM employees e1
JOIN employees e2 ON e1.manager_id = e2.employee_id;
CROSS JOIN — Cartesian product. Every row from Table A is paired with every row from Table B. Be careful — it can produce massive result sets.
8. What is the difference between UNION and UNION ALL?
Both combine the results of two SELECT queries.
UNIONremoves duplicate rows from the resultUNION ALLkeeps everything including duplicates — and is faster because it skips the deduplication step
sql
SELECT city FROM customers
UNION
SELECT city FROM suppliers;
-- Returns unique cities only
SELECT city FROM customers
UNION ALL
SELECT city FROM suppliers;
-- Returns all cities including duplicates
Aggregate Functions and GROUP BY
9. What are aggregate functions? Name the common ones.
Aggregate functions perform calculations across a set of rows and return a single value.
| Function | What It Does |
|---|---|
| COUNT() | Counts rows |
| SUM() | Adds up values |
| AVG() | Returns average |
| MAX() | Returns highest value |
| MIN() | Returns lowest value |
sql
SELECT dept_id, COUNT(*) AS total_employees, AVG(salary) AS avg_salary
FROM employees
GROUP BY dept_id
HAVING AVG(salary) > 50000;
10. What is the difference between COUNT(*) and COUNT(column_name)?
COUNT(*)counts all rows including those with NULL valuesCOUNT(column_name)counts only the rows where that specific column is NOT NULL
This is a sneaky question — make sure you know it.
Subqueries and Nested SELECTs
11. What is a subquery? What are its types?
A subquery is a query written inside another query. It runs first, and its result is used by the outer query.
Types:
- Single-row subquery — Returns one row
- Multi-row subquery — Returns multiple rows (used with
IN,ANY,ALL) - Correlated subquery — References a column from the outer query (runs once per row)
sql
-- Single-row subquery
SELECT name FROM employees
WHERE salary = (SELECT MAX(salary) FROM employees);
-- Multi-row subquery
SELECT name FROM employees
WHERE dept_id IN (SELECT dept_id FROM departments WHERE location = 'Mumbai');
12. What is the difference between a subquery and a JOIN?
Both retrieve data from multiple tables, but:
- Subqueries are easier to read for simple lookups and work well for aggregate comparisons
- JOINs are generally faster for large datasets because they let the query optimizer work more efficiently
- Use subqueries when the logic is filter-based; use JOINs when you need columns from multiple tables in the output
Indexes, Views, and Stored Procedures
13. What is an Index? Why do we use it?
An index is a database object that speeds up data retrieval. Think of it like the index at the back of a textbook — instead of scanning every page, you go straight to what you need.
However, indexes slow down INSERT, UPDATE, and DELETE operations because the index also needs to be updated. So they’re most useful on columns that are frequently searched or used in JOINs.
sql
CREATE INDEX idx_employee_name ON employees(name);
14. What is a View?
A view is a virtual table created from a SELECT query. It doesn’t store data itself — it just stores the query definition. Every time you query a view, it runs the underlying SELECT.
sql
CREATE VIEW high_salary_employees AS
SELECT name, salary FROM employees WHERE salary > 80000;
-- Now query it like a table
SELECT * FROM high_salary_employees;
Benefits: Simplifies complex queries, adds a layer of security by hiding sensitive columns, and makes code reusable.
15. What is a Stored Procedure?
A stored procedure is a precompiled block of SQL statements stored in the database. You can call it by name and pass parameters.
sql
CREATE PROCEDURE GetEmployeeByDept(IN dept_name VARCHAR(50))
BEGIN
SELECT * FROM employees WHERE department = dept_name;
END;
-- Call it
CALL GetEmployeeByDept('Engineering');
Why use it? Reduces network traffic, improves performance, and centralizes business logic inside the database.
Commonly Tested SQL Queries (Write These Live)
Here are queries you should be able to write without hesitation in an interview:
Find the second highest salary:
sql
SELECT MAX(salary) FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);
Find duplicate records:
sql
SELECT email, COUNT(*)
FROM employees
GROUP BY email
HAVING COUNT(*) > 1;
Get employees hired in the last 30 days:
sql
SELECT * FROM employees
WHERE hire_date >= CURDATE() - INTERVAL 30 DAY;
Rank employees by salary within each department:
sql
SELECT name, dept_id, salary,
RANK() OVER (PARTITION BY dept_id ORDER BY salary DESC) AS salary_rank
FROM employees;
Tips to Clear the SQL Round in 2026
1. Practice writing, not just reading. Use platforms like HackerRank, LeetCode SQL, or Mode Analytics. Reading answers won’t cut it.
2. Understand NULLs deeply. NULL behavior trips up a lot of freshers. NULL is not zero, not empty string — and comparisons with NULL using = always return false. Use IS NULL instead.
3. Know your window functions. In 2026, interviewers at good companies increasingly test ROW_NUMBER(), RANK(), DENSE_RANK(), and LAG()/LEAD(). These used to be “senior-level” topics — not anymore.
4. Be able to explain your query. After writing a query, interviewers often ask “Walk me through this.” Practice narrating your logic out loud.
5. Know the difference between correlated and non-correlated subqueries. Many freshers can write subqueries but can’t explain why a correlated one is slower.
6. Don’t ignore normalization. 1NF, 2NF, 3NF questions still appear. Know the concept with a simple real-world example.
FAQs
Q: How many SQL interview questions should I prepare for a fresher interview?
For most fresher roles, covering 30–40 core concepts and being able to write 15–20 practical queries is enough. Depth matters more than breadth.
Q: Is SQL enough to get a job as a fresher in 2026?
SQL alone won’t land you a job, but it’s a strong supporting skill. Pair it with Python or Java basics and you’ll stand out. For data analyst roles, SQL + Excel or SQL + Power BI is a solid combo.
Q: Which SQL dialect should I learn — MySQL, PostgreSQL, or SQL Server?
The core syntax is nearly identical across all of them. Learn standard SQL first. MySQL is the most common in smaller companies; PostgreSQL is favored in startups and data-heavy companies; SQL Server in enterprise/MNC environments.
Q: What is the best way to practice SQL before interviews?
HackerRank SQL, LeetCode Database problems, and SQLZoo are the best free resources for structured SQL practice.
For More interview Tips & latest Jobs Info Visit Jobupdates.in