Top 20 SQL Interview Questions and Answers for Freshers

Mou

October 28, 2025

Top 20 SQL Interview Questions and Answers for Freshers (2025)

SQL is one of the most important languages for anyone starting a career in IT, analytics, or software development. Interviewers often ask practical and conceptual SQL questions to test your understanding of how databases work.

Here’s a fresh set of simple and frequently asked SQL interview questions for freshers — with short and easy-to-understand answers.

1. What is the difference between SQL and MySQL?

Answer:

SQL is the language used to manage and query databases.

MySQL is a database management system (DBMS) that uses SQL to store and manage data.

Example: SQL is like the language, and MySQL is like a tool that understands and runs that language.

2. What is the difference between CHAR and VARCHAR data types?

Answer:

CHAR stores fixed-length data.

VARCHAR stores variable-length data.

Example:
If a column is CHAR(10) and you store “ABC”, it still takes 10 spaces.
VARCHAR(10) will only take 3 spaces for “ABC”.

3. What is the use of the DISTINCT keyword?

Answer:
DISTINCT is used to remove duplicate values from the result.

Example:

SELECT DISTINCT city FROM customers;

This will return each city name only once.

4. What is the purpose of the ORDER BY clause?

Answer:
ORDER BY is used to sort the result set in ascending (ASC) or descending (DESC) order.

Example:

SELECT * FROM employees ORDER BY salary DESC;

5. What is the LIMIT clause used for?

Answer:
LIMIT is used to restrict the number of rows returned by a query.

Example:

SELECT * FROM students LIMIT 5;

This returns only the first 5 records.

6. What is a NULL value in SQL?

Answer:
NULL means no value or missing value.
It is not the same as zero or an empty string.

Example:

SELECT * FROM employees WHERE manager_id IS NULL;

7. How can you replace NULL values with a default value?

Answer:
We can use the COALESCE() function.

Example:

SELECT name, COALESCE(bonus, 0) AS bonus_amount FROM employees;

If bonus is NULL, it will show 0 instead.

8. What is the difference between COUNT(*) and COUNT(column_name)?

Answer:

COUNT(*) counts all rows, including those with NULL values.

COUNT(column_name) counts only non-NULL values in that column.

9. What is the use of the LIKE operator?

Answer:
The LIKE operator is used to search for a pattern in a column.

Example:

SELECT * FROM employees WHERE name LIKE ‘A%’;

This finds all names starting with “A”.

10. What is the difference between INNER JOIN and OUTER JOIN?

Answer:

INNER JOIN: Returns only the matching rows from both tables.

OUTER JOIN: Returns all rows from one table and matches from the other.

Example:

SELECT e.name, d.dept_name
FROM employees e
LEFT JOIN departments d
ON e.dept_id = d.dept_id;

11. What is a Self Join?

Answer:
A Self Join means joining a table with itself.
It is useful when rows in a table are related to other rows in the same table.

Example:

SELECT a.name AS Employee, b.name AS Manager
FROM employees a
JOIN employees b ON a.manager_id = b.id;

12. What is a Stored Procedure?

Answer:
A Stored Procedure is a saved collection of SQL statements that can be executed whenever needed.
It helps in reusing logic and improving performance.

Example:

CREATE PROCEDURE getEmployees()
AS
SELECT * FROM employees;

13. What is the difference between a View and a Table?

Answer:

A Table stores actual data.

A View is a virtual table that shows data fetched from one or more tables.

Example:

CREATE VIEW employee_view AS
SELECT name, salary FROM employees WHERE salary > 50000;

14. What is the difference between UNION and UNION ALL?

Answer:

UNION removes duplicate rows.

UNION ALL includes duplicates.

Example:

SELECT name FROM employees
UNION
SELECT name FROM managers;

15. What are Transactions in SQL?

Answer:
A Transaction is a set of operations performed as a single unit of work.
It ensures data integrity using the ACID properties — Atomicity, Consistency, Isolation, and Durability.

Example:

BEGIN TRANSACTION;
UPDATE accounts SET balance = balance – 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;
COMMIT;

16. What is the difference between COMMIT and ROLLBACK?

Answer:

COMMIT saves the changes made by the transaction.

ROLLBACK undoes the changes.

Example:

ROLLBACK; — cancels last transaction

17. What is an Auto Increment field?

Answer:
It automatically generates a unique number for every new record.

Example:

CREATE TABLE students (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50)
);

18. What is the purpose of the CASE statement?

Answer:
It works like an IF-ELSE condition inside SQL.

Example:

SELECT name,
CASE
WHEN marks >= 60 THEN ‘Pass’
ELSE ‘Fail’
END AS Result
FROM students;

19. What is the difference between Clustered and Non-Clustered Index?

Answer:

Clustered Index: Stores data physically in sorted order (only one per table).

Non-Clustered Index: Creates a separate structure to store index information (can have multiple).

Example:

CREATE CLUSTERED INDEX idx_empid ON employees(emp_id);

20. What are the advantages of using SQL?

Answer:

Easy to learn and use.

Efficient data retrieval.

Can handle large amounts of data.

Allows secure data access and sharing.

Used by almost all major database systems (MySQL, Oracle, SQL Server, PostgreSQL).

✅ Final Tips for SQL Freshers

Focus on understanding the logic behind queries, not just syntax.

Practice SELECT, JOIN, GROUP BY, and WHERE queries daily.

Try solving small real-life examples like student marks, product sales, or employee records.

💡 Conclusion

These SQL questions are the most commonly asked in fresher-level interviews. If you understand these well, you’ll be ready to answer confidently and even handle tricky follow-ups.

You can find more SQL interview question sets and technical learning tips at glimsy.in — your one-stop guide for interview preparation and English speaking resources.

Leave a Comment