Skip to content
FACE PREP CAMPUS

Top 20 SQL Interview Questions and Answers | 2025–2026

Structured Query Language (SQL) is the backbone of modern data handling and is a must-know for developers, data analysts, and software engineers. If you’re preparing for tech interviews in 2025–2026, here’s a comprehensive guide to the top 20 SQL interview questions with detailed explanations and real-world examples.


1. What is SQL?

SQL stands for Structured Query Language. It is used to interact with databases—to create, retrieve, update, and delete data.
Example:

This command fetches all records from the “employees” table.


2. Types of SQL Commands

SQL commands are categorized into:

  • DDL (CREATE, ALTER, DROP)
  • DML (INSERT, UPDATE, DELETE)
  • DQL (SELECT)
  • DCL (GRANT, REVOKE)
  • TCL (COMMIT, ROLLBACK)

    Example:

3. What is a Primary Key?

A primary key uniquely identifies each record and must not contain NULLs.

Example:


4. What is a Foreign Key?

A foreign key links one table to another using the primary key of the second table.
Example:


5. Difference between WHERE and HAVING

  • WHERE filters rows before grouping
  • HAVING filters after grouping
    Example:

6. What is a JOIN? Types?

JOINs combine rows from two or more tables.
Types:
->INNER
->LEFT
->RIGHT
->FULL OUTER
->CROSS, SELF

Example:


7. INNER JOIN vs LEFT JOIN

  • INNER JOIN: returns only matching rows.
  • LEFT JOIN: returns all rows from the left table, and matched rows from the right.
    Example:

8. What is a Subquery?

A subquery is a query nested inside another query.
Example:


9. DELETE vs TRUNCATE vs DROP

  • DELETE: removes specific rows
  • TRUNCATE: removes all rows quickly
  • DROP: deletes table structure
    Example:

10. What is Normalization?

Organizing data to reduce redundancy.
Forms: 1NF, 2NF, 3NF
Example:
Split table storing customer & order details into two linked tables.


11. What is a View?

A virtual table based on a query.
Example:


12. What is an Index?

Indexes speed up data retrieval.
Example:


13. UNION vs UNION ALL

  • UNION: removes duplicates
  • UNION ALL: includes duplicates
    Example:

14. What are Constraints?

Constraints are rules applied to table columns to maintain data accuracy, like NOT NULL, UNIQUE, CHECK, and FOREIGN KEY. They help enforce data integrity.

Types: NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK, DEFAULT
Example:


15. Aggregate Functions

These are functions that perform calculations on multiple rows and return a single result — like SUM(), AVG(), COUNT(), etc. They’re commonly used with GROUP BY.

Functions: COUNT(), SUM(), AVG(), MAX(), MIN()
Example:


16. What is a Stored Procedure?

A stored procedure is a reusable set of SQL statements saved in the database. It simplifies complex operations and improves performance.

Example:


17. What is a Trigger?

A trigger is an automatic action that runs in response to events like INSERT, UPDATE, or DELETE on a table. It’s used to enforce rules or update data automatically.

Example:


18. NULL vs 0

NULL means a missing or unknown value, while 0 is a definite numeric value. They are not the same and behave differently in comparisons.

  • NULL: unknown or missing value
  • 0: a numeric value
    Example:

19. How to Find Duplicates

Use GROUP BY and HAVING COUNT(*) > 1 to identify repeated values in a column. It groups similar entries and filters out those that occur more than once.

Example:


20. Find the Second Highest Salary

Use a subquery with MAX() to find the highest salary less than the maximum, effectively returning the second highest value.

Example:


Final Thoughts

SQL is more than just a query language—it’s a fundamental skill for anyone working in data or development. These 20 questions cover the basics and more. Practice them, build your own queries, and you’ll be ready for any SQL round.

At FACE Prep Campus, we don’t just teach SQL theory. We help students apply SQL in real-world projects, crack interview rounds, and become job-ready. Join our UG programs in Computer Science, BCA, or BCom with FinTech and get hands-on with SQL, Python, and more.

Your career in tech starts with strong fundamentals. Learn with FACE Prep.


Author

FACE Prep Campus