Home/Resources/Blog/Top 25 SQL Interview Questions and Answers for Freshers in 2026
Interview PreparationExpectin Team28 Oct 202611 min read

Top 25 SQL Interview Questions and Answers for Freshers in 2026

Prepare for SQL interviews with 25 questions and answers covering queries, filtering, joins, aggregate functions, subqueries, database keys, indexes, and practical SQL examples for freshers in 2026.

LWX
Top 25 SQL Interview Questions and Answers for Freshers in 2026

On this page

  • Top 25 SQL Interview Questions and Answers for Freshers in 2026
  • SQL Fundamentals
  • 1. What is SQL?
  • 2. What is a database?
  • 3. What is a table in SQL?
  • 4. What are the main types of SQL commands?
  • 5. What is the difference between a primary key and a foreign key?
  • SQL Queries and Filtering
  • 6. What is the SELECT statement?
  • 7. What is the WHERE clause?
  • 8. What is the difference between WHERE and HAVING?
  • 9. What does ORDER BY do?
  • 10. What is the difference between DELETE, TRUNCATE, and DROP?
  • SQL Functions and Grouping
  • 11. What are aggregate functions in SQL?
  • 12. What is GROUP BY?
  • 13. What is the difference between COUNT(*) and COUNT(column)?
  • 14. What is NULL in SQL?
  • 15. What is the difference between IN and BETWEEN?
  • SQL Joins
  • 16. What is a JOIN in SQL?
  • 17. What is an INNER JOIN?
  • 18. What is a LEFT JOIN?
  • 19. What is the difference between INNER JOIN and LEFT JOIN?
  • Subqueries, Indexes, and Database Design
  • 20. What is a subquery?
  • 21. What is an index in SQL?
  • 22. What is database normalization?
  • 23. What is a transaction in SQL?
  • Practical SQL Interview Questions
  • 24. How do you find the second-highest distinct salary?
  • 25. How do you find duplicate values in a table?
  • How to Prepare for an SQL Interview
  • Practise writing queries
  • Understand database relationships
  • Learn to explain your approach
  • Practise query optimization basics
  • Learn the database used by your target employer
  • Find Database and Software Jobs on Expectin
  • Frequently Asked Questions
  • Is SQL important for freshers?
  • Which SQL topics should I learn first?
  • Are SQL interview questions the same for every company?
  • Should I learn PostgreSQL or MySQL first?
  • How can I practise SQL?
  • Where can I find jobs that require SQL?

Top 25 SQL Interview Questions and Answers for Freshers in 2026

SQL (Structured Query Language) is widely used to store, retrieve, and manage data in relational databases. It is an essential skill for many software development, backend engineering, database administration, and data analytics roles.

If you are preparing for an entry-level IT interview, understanding SQL fundamentals and practising queries can help you answer technical questions with confidence.

In this Expectin guide, we cover 25 common SQL interview questions, clear explanations, and practical examples to help you prepare for your next opportunity.

SQL Fundamentals

1. What is SQL?

SQL stands for Structured Query Language. It is used to interact with relational database management systems such as PostgreSQL, MySQL, SQL Server, and Oracle Database.

SQL can be used to:

  • Retrieve records from tables.

  • Insert new records.

  • Update existing records.

  • Delete records.

  • Create and modify database structures.

  • Control access and manage transactions, depending on database permissions.

2. What is a database?

A database is an organized collection of data that can be stored, accessed, and managed by software.

A relational database stores data in tables containing rows and columns. Tables can be related through keys.

For example, a job portal might store candidates in one table, job listings in another, and applications in a third table.

3. What is a table in SQL?

A table organizes related data into rows and columns.

For example, an employees table might contain:

idnamedepartmentsalary
1AnuIT40000
2RaviHR35000
3MeenaIT45000

Each row represents a record, and each column represents an attribute.

4. What are the main types of SQL commands?

SQL commands are commonly grouped into these categories:

  • DDL (Data Definition Language): CREATE, ALTER, DROP

  • DML (Data Manipulation Language): INSERT, UPDATE, DELETE

  • DQL (Data Query Language): SELECT is commonly classified here

  • DCL (Data Control Language): GRANT, REVOKE

  • TCL (Transaction Control Language): COMMIT, ROLLBACK, SAVEPOINT

Classifications may vary slightly between learning materials and database systems.

5. What is the difference between a primary key and a foreign key?

A primary key uniquely identifies each row in a table. It must be unique and cannot contain NULL values.

A foreign key references a key in another table, or in some database designs, the same table. It helps maintain referential integrity.

Example:

CREATE TABLE departments (
    department_id INT PRIMARY KEY,
    department_name VARCHAR(100)
);

CREATE TABLE employees (
    employee_id INT PRIMARY KEY,
    employee_name VARCHAR(100),
    department_id INT,
    FOREIGN KEY (department_id)
        REFERENCES departments(department_id)
);

Here, department_id is the primary key in departments and a foreign key in employees.

SQL Queries and Filtering

6. What is the SELECT statement?

SELECT retrieves data from a database.

Example:

SELECT name, salary
FROM employees;

This query returns the name and salary columns for all rows in the employees table.

Use only the columns you need rather than selecting every column by default in production queries.

7. What is the WHERE clause?

WHERE filters rows according to a condition.

Example:

SELECT *
FROM employees
WHERE department = 'IT';

This returns employees whose department is IT.

8. What is the difference between WHERE and HAVING?

WHERE filters rows before grouping and aggregation.

HAVING filters groups after GROUP BY has formed them.

Example:

SELECT department, COUNT(*) AS employee_count
FROM employees
WHERE salary >= 30000
GROUP BY department
HAVING COUNT(*) > 1;

This query first filters employees by salary, groups the remaining rows by department, and then returns departments with more than one qualifying employee.

9. What does ORDER BY do?

ORDER BY sorts query results by one or more columns.

Example:

SELECT name, salary
FROM employees
ORDER BY salary DESC;

DESC sorts in descending order. ASC sorts in ascending order and is the default in many SQL implementations.

10. What is the difference between DELETE, TRUNCATE, and DROP?

  • DELETE removes selected rows and can use a WHERE condition.

  • TRUNCATE removes all rows from a table in database systems that support it.

  • DROP removes a database object, such as a table.

Their transaction behavior, identity-reset behavior, locking, and permission requirements vary by database system. Always verify the behavior of your database before executing destructive commands.

Example:

DELETE FROM employees
WHERE employee_id = 10;

This deletes the row matching the specified employee ID.

SQL Functions and Grouping

11. What are aggregate functions in SQL?

Aggregate functions calculate a result from multiple rows.

Common examples include:

  • COUNT() counts rows or non-NULL values, depending on its argument.

  • SUM() calculates a total.

  • AVG() calculates an average.

  • MIN() returns the minimum value.

  • MAX() returns the maximum value.

Example:

SELECT
    COUNT(*) AS total_employees,
    AVG(salary) AS average_salary,
    MAX(salary) AS highest_salary
FROM employees;

12. What is GROUP BY?

GROUP BY groups rows that share the same values in specified columns. It is often used with aggregate functions.

Example:

SELECT department, COUNT(*) AS total
FROM employees
GROUP BY department;

This returns the number of employees in each department.

13. What is the difference between COUNT(*) and COUNT(column)?

COUNT(*) counts rows.

COUNT(column) counts rows where that column is not NULL.

Example:

SELECT
    COUNT(*) AS total_rows,
    COUNT(department) AS rows_with_department
FROM employees;

The two counts may differ when the department column contains NULL values.

14. What is NULL in SQL?

NULL represents missing or unknown information. It is not the same as zero or an empty string.

Use IS NULL or IS NOT NULL to test for NULL values.

Example:

SELECT *
FROM employees
WHERE department IS NULL;

Comparisons such as department = NULL do not correctly test for NULL values in standard SQL.

15. What is the difference between IN and BETWEEN?

IN checks whether a value matches one of the values in a list.

BETWEEN checks whether a value falls within an inclusive range.

Example:

SELECT *
FROM employees
WHERE department IN ('IT', 'HR');
SELECT *
FROM employees
WHERE salary BETWEEN 30000 AND 50000;

The BETWEEN boundaries are inclusive in standard SQL.

SQL Joins

16. What is a JOIN in SQL?

A JOIN combines related rows from two or more tables based on a join condition.

For example, an employee table may contain a department ID that references a department table.

17. What is an INNER JOIN?

An INNER JOIN returns rows where the join condition matches in both tables.

Example:

SELECT e.employee_name, d.department_name
FROM employees e
INNER JOIN departments d
    ON e.department_id = d.department_id;

Employees without a matching department are excluded from this result.

18. What is a LEFT JOIN?

A LEFT JOIN returns every row from the left table and matching rows from the right table. If no match exists, columns from the right table contain NULL.

Example:

SELECT e.employee_name, d.department_name
FROM employees e
LEFT JOIN departments d
    ON e.department_id = d.department_id;

This can be useful when you need to list all employees, including those without a matching department.

19. What is the difference between INNER JOIN and LEFT JOIN?

An INNER JOIN returns only matching rows from both sides.

A LEFT JOIN preserves all rows from the left table, even if no right-side match exists.

Choose the join based on the result you need, not simply on which syntax is more common.

Subqueries, Indexes, and Database Design

20. What is a subquery?

A subquery is a query nested inside another SQL statement.

Example:

SELECT name, salary
FROM employees
WHERE salary > (
    SELECT AVG(salary)
    FROM employees
);

This returns employees whose salary is higher than the average salary calculated by the inner query.

21. What is an index in SQL?

An index is a database structure that can help locate rows more efficiently for supported queries.

Indexes are often useful for columns frequently used in filtering, joining, or sorting. However, they consume storage and can increase the cost of inserts, updates, and deletes.

Example:

CREATE INDEX idx_employees_department
ON employees(department);

The benefit depends on the database, data distribution, and query patterns. Review query plans and performance before adding indexes.

22. What is database normalization?

Normalization is the process of organizing relational data to reduce unnecessary duplication and avoid certain data anomalies.

Common concepts include first normal form (1NF), second normal form (2NF), and third normal form (3NF).

For example, storing department details in a separate department table can reduce repeated department information across employee records.

Database design also involves trade-offs. Some systems intentionally use denormalization for particular performance or reporting needs.

23. What is a transaction in SQL?

A transaction groups database operations into a logical unit of work.

Transactions are commonly discussed using ACID properties:

  • Atomicity: The transaction succeeds as a unit or is rolled back as a unit.

  • Consistency: The transaction preserves defined database rules.

  • Isolation: Concurrent transactions are controlled according to the isolation level.

  • Durability: Committed changes persist according to the database's guarantees.

Example:

BEGIN;

UPDATE accounts
SET balance = balance - 100
WHERE account_id = 1;

UPDATE accounts
SET balance = balance + 100
WHERE account_id = 2;

COMMIT;

The exact transaction syntax and behavior vary by database. In real financial systems, validate account conditions, handle errors, and use appropriate concurrency controls before committing changes.

Practical SQL Interview Questions

24. How do you find the second-highest distinct salary?

A common approach is to use a subquery with MAX().

SELECT MAX(salary) AS second_highest_salary
FROM employees
WHERE salary < (
    SELECT MAX(salary)
    FROM employees
);

This returns the second-highest distinct salary when one exists. It returns NULL if there is no lower distinct salary.

Another option is to use a window function such as DENSE_RANK() when you need to rank values or return multiple employees who share the same salary.

25. How do you find duplicate values in a table?

Use GROUP BY with HAVING to identify values that appear more than once.

Example:

SELECT email, COUNT(*) AS occurrences
FROM employees
GROUP BY email
HAVING COUNT(*) > 1;

This finds email values that occur multiple times. Whether duplicate emails should be allowed depends on the database design and business requirements.

How to Prepare for an SQL Interview

Practise writing queries

Work with sample tables and practise filtering, sorting, joins, aggregation, and subqueries. Focus on understanding the result, not just memorizing syntax.

Understand database relationships

Learn how primary keys, foreign keys, and joins work together. This helps you solve real-world data retrieval problems.

Learn to explain your approach

Describe how your query works, what edge cases exist, and how you would handle NULL values or duplicate records.

Practise query optimization basics

Understand indexes, query plans, and why retrieving unnecessary columns or joining large tables inefficiently can affect performance.

Learn the database used by your target employer

SQL syntax and features can differ across PostgreSQL, MySQL, SQL Server, Oracle, and other database systems. Review the relevant documentation and practise in the environment used by the role.

Find Database and Software Jobs on Expectin

SQL is useful across several career paths, including:

  • SQL Developer

  • Backend Developer

  • Software Engineer

  • Data Analyst

  • Database Administrator

  • Business Intelligence Developer

  • Python Developer

Job requirements vary by employer. Review the skills, experience range, location, and qualifications listed in each vacancy.

Visit https://expectin.com to explore available job opportunities and find positions that match your skills and career goals.

Frequently Asked Questions

Is SQL important for freshers?

SQL is useful for many entry-level software, backend, data, and database roles. The depth required depends on the job description.

Which SQL topics should I learn first?

Start with SELECT, WHERE, ORDER BY, GROUP BY, aggregate functions, joins, NULL handling, and basic subqueries. Then practise keys, indexes, normalization, and transactions.

Are SQL interview questions the same for every company?

No. Some interviews focus on basic queries, while others include complex joins, window functions, query optimization, and database design.

Should I learn PostgreSQL or MySQL first?

Both are useful relational databases. Choose based on your target roles and practise the SQL features required by those employers.

How can I practise SQL?

Use a local database or an online SQL practice environment with sample datasets. Write queries, test edge cases, and check that your results are correct.

Where can I find jobs that require SQL?

Visit https://expectin.com to explore current vacancies and check the database skills and qualifications required for each position.


About Expectin

Expectin helps job seekers explore career opportunities and access career-related resources. Keep practising SQL, strengthen your technical fundamentals, and take the next step in your career.

Ready to put this into action?

Build my resumeCheck my ATS scoreBrowse jobs
Expectin Logo

Great platform for the job seeker that passionate about startups. Find your dream job easier.

Explore

  • Find Jobs
  • Job Portal India
  • Government Jobs
  • Resume Builder
  • ATS Resume Checker
  • Companies
  • For Employers
  • White Label Solution
  • Recruitment Platform Software

About

  • About Expectin
  • Company
  • Terms & Conditions
  • Privacy Policy
  • Refund Request
  • Delete Account

Resources

  • Blog
  • Video Guide
  • Contact Us

Stay Updated

Get AI career tips, job alerts and resume advice straight to your inbox.

No spam. Unsubscribe anytime.

Contact Us

We're here to help!

2026 ©Expectin. All rights reserved.

@Powered by Appzeon