Jawab AI

Interview guides / SQL interview questions

Top SQL Interview Questions and Answers for 2026

Welcome to the ultimate SQL interview preparation guide for 2026. Designed specifically for freshers and early professionals from tier-2 and tier-3 colleges in India, this guide covers everything from basic queries to advanced database concepts. You will find real, spoken sample answers, inline SQL snippets, and clear explanations of what interviewers look for.

Try Jawab AI free

Basic SQL Queries

  1. 1. What is SQL and why do we use it?

    Interviewer is checking your foundational understanding. Say: SQL stands for Structured Query Language. We use it to communicate with relational databases to store, retrieve, update, and manage data efficiently.

  2. 2. What is the difference between WHERE and HAVING clauses?

    Interviewer wants to see if you know aggregation rules. Say: WHERE is used to filter rows before any grouping takes place. HAVING is used to filter groups after the GROUP BY clause is applied, usually with aggregate functions like COUNT or SUM.

  3. 3. How do you find the second highest salary from an Employee table?

    Interviewer tests your query-writing logic. Say: We can use a subquery or limit. For example: SELECT MAX(salary) FROM employee WHERE salary < (SELECT MAX(salary) FROM employee); or use LIMIT and OFFSET depending on the SQL dialect.

  4. 4. What are DISTINCT and LIMIT clauses used for?

    Interviewer checks basic syntax familiarity. Say: DISTINCT removes duplicate rows from the result set, while LIMIT restricts the number of rows returned by the query, which is helpful for large datasets.

  5. 5. Write a query to count the number of employees in each department.

    Interviewer tests basic GROUP BY usage. Say: We group by the department column. For example: SELECT department, COUNT(*) FROM employee GROUP BY department;

Joins and Relationships

  1. 6. Explain the different types of joins in SQL.

    Interviewer wants a clear conceptual breakdown. Say: INNER JOIN returns matching rows in both tables. LEFT JOIN returns all rows from the left table and matching rows from the right. RIGHT JOIN does the opposite. FULL OUTER JOIN returns all rows when there is a match in either table.

  2. 7. What is a Self Join and when would you use it?

    Interviewer checks advanced join understanding. Say: A self join is when a table is joined with itself. We use it when storing hierarchical data, such as an employee table where an employee column references a manager id within the same table.

  3. 8. What is the difference between UNION and UNION ALL?

    Interviewer tests performance awareness. Say: UNION combines result sets and removes duplicate rows, which takes extra processing time. UNION ALL combines results including duplicates, making it much faster.

  4. 9. Can you explain a Cross Join with an example?

    Interviewer checks Cartesian product knowledge. Say: A CROSS JOIN returns the Cartesian product of two tables. If table A has 3 rows and table B has 4 rows, the result has 12 rows. Syntax: SELECT * FROM table1 CROSS JOIN table2;

  5. 10. What happens when you join two tables without a ON condition?

    Interviewer checks potential mistake awareness. Say: It results in a Cartesian product where every row of the first table is paired with every row of the second table, often hanging the system if tables are large.

Aggregation and Functions

  1. 11. What are aggregate functions? Give some examples.

    Interviewer tests basic calculation knowledge. Say: Aggregate functions perform a calculation on a set of values and return a single value. Examples include COUNT, SUM, AVG, MAX, and MIN.

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

    Interviewer checks handling of NULL values. Say: COUNT(*) counts all rows in the table including those with NULL values. COUNT(column_name) counts only the rows where the specified column has non-NULL values.

  3. 13. Explain scalar functions with an example.

    Interviewer checks built-in function knowledge. Say: Scalar functions operate on a single value and return a single value. Examples include string functions like UPPER(), LOWER(), or LENGTH(). For example: SELECT UPPER(name) FROM employee;

  4. 14. How does the CASE statement work in SQL?

    Interviewer tests conditional logic handling. Say: The CASE statement acts like an if-else condition inside a query. It evaluates conditions and returns a specific value when the first condition is met. Example: SELECT name, CASE WHEN salary > 50000 THEN 'High' ELSE 'Low' END FROM employee;

  5. 15. What are window functions in SQL?

    Interviewer checks advanced analytical skills. Say: Window functions perform calculations across a set of table rows that are somehow related to the current row, without grouping rows into a single output like GROUP BY does.

Advanced Concepts and Optimization

  1. 16. What is indexing and why is it important?

    Interviewer tests database performance knowledge. Say: An index is a database structure that improves the speed of data retrieval operations on a table at the cost of additional writes and storage space. It acts like an index in the back of a book.

  2. 17. What is the difference between clustered and non-clustered indexes?

    Interviewer checks deep indexing concepts. Say: A clustered index defines the physical order of data in the table, so a table can have only one. A non-clustered index is a separate structure containing pointers to the data, and a table can have many.

  3. 18. What are ACID properties in a database?

    Interviewer tests transaction management knowledge. Say: ACID stands for Atomicity, Consistency, Isolation, and Durability. These properties ensure that database transactions are processed reliably and data integrity is maintained.

  4. 19. What is a stored procedure?

    Interviewer checks procedural SQL knowledge. Say: A stored procedure is a prepared SQL code that you can save and reuse over and over again, helping reduce network traffic and improve modularity.

  5. 20. How do you handle NULL values in SQL queries?

    Interviewer tests bug prevention techniques. Say: We can handle NULL values using functions like COALESCE or ISNULL to provide default fallback values. For example: SELECT COALESCE(phone, 'Not Provided') FROM employee;

Tips for the interview

  • Practice writing queries out on paper or a whiteboard during your preparation.
  • Always explain your thought process clearly before jumping into writing the SQL code.
  • Be ready to trace your queries with sample data provided by the interviewer.
  • Understand the underlying table schema completely before writing complex joins.

Blank on a question? Not anymore.

Jawab AI listens to your interview and shows a clear answer on your screen in seconds, based on your resume. The desktop app stays invisible when you share your screen. Your first 3 sessions of 10 minutes are free.

Try Jawab AI free

More interview guides

These are commonly asked questions with sample answers, not an official list. Hiring processes change, so check the company's careers page for the current one. Jawab AI is not affiliated with any company named here.