Get courses worth Rs. 12,000 for FREE! 🔥 Only for selected students.

SQL Interview Questions and Answers for 2026

Introduction

SQL is an essential skill for data analysts, data scientists, software developers, and database professionals. If you are preparing for a SQL interview, knowing basic queries is only the starting point. Interviewers may also want to see how well you understand databases, work with real-world data, solve problems, and improve query performance.

In this guide, we have put together SQL interview questions and answers for 2026 to help you prepare for different types of interviews. It covers everything from basic SQL concepts, databases, keys, and constraints to joins, subqueries, aggregate functions, indexing, window functions, and query optimisation.

Whether you are a fresher preparing for your first interview, an experienced professional looking for a new opportunity, or a recruiter looking for the right questions to ask, this blog will help you understand what to expect in a SQL interview and prepare with confidence.

SQL Interview Questions

General SQL Interview Questions

Before getting into technical questions, an interviewer may start with a few general questions about your experience with SQL. These questions help them understand your familiarity with SQL and how you have used it in your studies, projects, or previous roles.

If you have limited SQL experience, don’t worry. Your interviewer will usually gauge your experience level from your resume. You also do not need to know every SQL dialect. Most SQL dialects follow the same basic concepts, so knowing one well gives you a good foundation for learning others.

What is SQL?

SQL stands for Structured Query Language. It is a language for working with relational databases. SQL allows users to retrieve, add, update, and delete data stored in database tables.

What are the major types of SQL commands?

Types of SQL commands are generally divided into five, based on what they are used for:

  • DDL (Data Definition Language) – To create and modify database structures.
  • DML (Data Manipulation Language) – To add, update, and delete data.
  • DQL (Data Query Language) – To retrieve data from the database.
  • TCL (Transaction Control Language) – Used to manage database transactions.
  • DCL (Data Control Language) – Used to manage access and permissions in a database.

What is a database?

A database is a structured system for storing and managing data electronically. It allows users to easily add, find, update, and organise information. Databases can use structures such as tables, indexes, and relationships to organise data efficiently.

What is a transaction in SQL?

A transaction is a cluster of database operations handled as a single unit. It ensures that the modifications are applied correctly and helps prevent data inconsistencies by using commands like COMMIT to save changes and ROLLBACK to undo them.

What are common challenges in working with SQL databases?

Working with SQL databases can come with challenges such as slow queries, deadlocks, and limited storage. Changes to the database structure can also affect existing applications. Poor database design, duplicate data, and incorrect transaction handling can lead to data inconsistencies and other issues.

What is a primary key?

A primary key is a column or group of columns that identifies each record in a table. It does not allow duplicate or NULL values.

A table can have only one primary key, but that key can contain more than one column. A primary key can also be a surrogate key, such as an automatically generated number or UUID, instead of a business value.

What is a foreign key?

A foreign key is basically a column or set of columns in one table that references a key, usually the primary key, in another table. It establishes relationships between tables and maintains data consistency.

How do you find duplicate rows in a table?

You can find duplicate rows by using GROUP BY on the columns you want to check and then using HAVING COUNT(*) > 1. This groups matching records and shows the values that appear more than once.

What is the difference between UNION and UNION ALL?

UNION combines the results of two queries and removes duplicate rows. UNION ALL combines the results without removing duplicates. Because UNION ALL does not check for duplicates, it is generally faster.

What are SQL dialects? Give some examples.

SQL dialects are different versions or implementations of SQL used by various database systems. They follow the same basic SQL concepts but can differ in syntax, functions, and additional features.

Some common SQL dialects include MySQL, PostgreSQL, Microsoft SQL Server, Oracle Database, and SQLite.

What are the main uses of SQL?

SQL is mainly used to store, retrieve, update, and delete data in databases. It is also used to create and manage database structures, generate reports, analyse data, control user access, and manage transactions. SQL makes it easier to work with large amounts of structured data.

What is a MERGE statement?

The MERGE statement combines INSERT, UPDATE, and DELETE operations in a single statement based on specified conditions. It is commonly used to synchronise data between two tables and handle upsert operations.

What is the difference between horizontal and vertical partitioning?

Horizontal partitioning splits a table by rows. For example, you could keep data from different years in separate sections. Vertical partitioning splits a table by columns, such as keeping commonly used details separate from large or less frequently used data. Both methods can make it easier and faster for the database to work with large amounts of data.

What are the main applications of SQL?

SQL is mainly used to manage and work with data stored in relational databases. Its common applications include:

  • Creating and modifying database tables
  • Adding, updating, and deleting data
  • Retrieving data from databases
  • Filtering, sorting, and grouping data
  • Combining data from multiple tables
  • Summarising data using aggregate functions

What is an SQL statement?

An SQL statement is simply a command you give to a database to tell it what you want it to do. Depending on the task, you can use it to retrieve, add, change, or delete data, or to manage database objects and permissions. Common SQL statements include SELECT, CREATE, DELETE, DROP, and REVOKE.

What is an SQL query?

An SQL query is a command that interacts with the data stored in a database. It helps you retrieve the information you need, filter or organise results, and work with data from different tables.

SQL queries are mainly used to retrieve or modify data. This includes tasks such as finding records, adding new data, updating existing information, and deleting data from a database.

What is an SQL subquery?

A subquery is a query placed inside another SQL query. It is also known as an inner query and can be used in clauses such as SELECT, FROM, WHERE, and UPDATE. A subquery can also contain another subquery. In such cases, the innermost query runs first, and the outer query uses its result.

What is an SQL join?

An SQL join combines data from two or more tables based on a related column. Joins are commonly used when the required information is stored across multiple tables.

The main types of joins include INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL OUTER JOIN.

What is a trigger in SQL?

A trigger in SQL is a database action that automatically happens when a specific event occurs in a table or database. Common events include INSERT, UPDATE, and DELETE.

Triggers are usually used to maintain data integrity, enforce business rules, track changes, and automate database tasks.

What is an SQL comment?

An SQL comment is a note added to SQL code to explain what a query or a particular section of code does. The database ignores comments when it executes the query. They can make SQL code easier to understand, maintain, and review.

What is an SQL alias?

An SQL alias is a temporary name given to a table or column within a query. Aliases make queries easier to read and can simplify queries that work with multiple tables or long column names. The AS keyword is commonly used to assign an alias.

What is a sequence in SQL?

A sequence generates a series of sequential, typically unique, numbers in a database. It is often used to create record IDs, such as primary keys, so you don’t have to enter the numbers manually.

What are aggregate functions in SQL?

Aggregate functions are used when you want to calculate something from multiple rows and get a single result. For example, you can use them to find the total, average, number of records, or highest and lowest values.

Some common aggregate functions are:

  • SUM() – Finds the total.
  • AVG() – Finds the average.
  • COUNT() – Counts the records.
  • MAX() – Finds the highest value.
  • MIN() – Finds the lowest value.

Technical SQL Interview Questions

Once interviewers cover the basics, they may move on to more technical SQL concepts. These questions are designed to check how well you understand databases, queries, relationships, and SQL operations.

When answering technical questions, try to keep your response short, clear, and relevant. You do not need to explain everything you know unless the interviewer asks for more details. Focus on the question, explain the concept in simple words, and show that you understand how it works.

 What types of SQL commands do you know?

SQL commands are generally divided into five categories:

  • Data Definition Language (DDL): Used to create and modify the structure of database objects.
  • Data Manipulation Language (DML): Used to add, update, and delete data in a database.
  • Data Control Language (DCL): Used to manage access and permissions.
  • Transaction Control Language (TCL): Used to manage database transactions.
  • Data Query Language (DQL): Used to retrieve data from a database.

What is DBMS, and what types of DBMS do you know?

DBMS stands for Database Management System. It is software used to store, manage, retrieve, update, and organise data in a database.

Common types of DBMS include relational, hierarchical, network, object-oriented, and graph databases.

What is RDBMS? Give some examples.

RDBMS stands for Relational Database Management System. It stores data in tables and allows you to create relationships between tables using related columns or keys.

Common RDBMS examples include MySQL, PostgreSQL, Oracle Database, and MariaDB.

What are tables and fields in SQL?

A table is a collection of related data organised into rows and columns. A field refers to a column in a table and represents a particular type of information stored for each record.

What types of SQL subqueries do you know?

Common types of SQL subqueries include:

  • Single-row subquery: Returns a single row.
  • Multiple-row subquery: Returns multiple rows.
  • Multiple-column subquery: Returns multiple columns.
  • Correlated subquery: Depends on values from the outer query.
  • Nested subquery: A subquery placed inside another subquery.

 What is a constraint, and why are constraints used?

A constraint is simply a rule that tells the database what kind of data can be stored in a table. It helps prevent incorrect or unwanted data and keeps the information accurate and consistent.

What SQL constraints do you know?

Some of the most commonly used SQL constraints are:

  • DEFAULT: Automatically adds a value when no value is provided.
  • UNIQUE: Ensures duplicate values are not entered.
  • NOT NULL: Makes sure a column cannot be left empty.
  • PRIMARY KEY: Uniquely identifies each record in a table and cannot contain NULL values.
  • FOREIGN KEY: Connects two tables by linking a column to a key in another table.

What types of joins do you know?

Joins help you bring together related data from different tables. The commonly used SQL joins are:

  • INNER JOIN: Shows only the records that match in both tables.
  • LEFT JOIN: Shows every record from the left table along with matching records from the right table.
  • RIGHT JOIN: Shows every record from the right table along with matching records from the left table.
  • FULL OUTER JOIN: Shows all records from both tables, whether they have a match or not.

Available joins may differ slightly depending on the database system you use.

What are the pros and cons of using indexes in SQL databases?

Indexes can make database queries much faster by helping the database find data more quickly. However, they also use extra storage and can slow INSERT, UPDATE, and DELETE operations because the indexes must be updated whenever the data changes.

What is a unique key in SQL?

A unique key is a column, or a combination of columns, that prevents duplicate values. Unlike a primary key, a unique key can generally allow NULL values.

The way NULL values are handled can vary between database systems. For example, SQL Server typically allows one NULL in a unique column, while PostgreSQL, Oracle, and MySQL can allow multiple NULL values.

What is an SQL index?

An SQL index helps a database find data faster without searching through the entire table every time. It stores selected information from a table in an organised way, which can speed up data retrieval, especially for large tables.

What types of indexes do you know?

Some common types of indexes include:
  • Unique index: Prevents duplicate values in the indexed column or columns.
  • Clustered index: Determines how data is physically organised or accessed based on the database system. A table generally has only one clustered index.
  • Non-clustered index: Stores index information separately from the main table data and allows multiple indexes on a table.

The exact behaviour of clustered and non-clustered indexes depends on the database system.

What is a schema?

A schema defines the structure and organisation of database objects. It can contain objects such as tables, views, indexes, functions, procedures, and triggers. Schemas can also help organise database objects and manage access permissions.

What is a SQL operator?

A SQL operator is a symbol, set of symbols, or keyword used to perform a specific action in a query. It is often used with the WHERE clause to set conditions and filter the data you want to retrieve.

What types of SQL operators do you know?

SQL operators perform different operations in a query. The main types include:

  • Arithmetic operators: Used for calculations, such as +, -, *, and /.
  • Comparison operators: Used to compare values, such as =, >, <, and >=.
  • Compound operators: Combine an arithmetic operation with an assignment, such as +=, -=, *=, and /=.
  • Logical operators: Used to combine or define conditions, such as AND, OR, NOT, and BETWEEN.
  • String operators: Used when working with text and pattern matching, such as %, _, and +.
  • Set operators: Used to merge the results of two or more queries, such as UNION, UNION ALL, INTERSECT, and EXCEPT.

What is a clause?

A clause is a part of an SQL query used to specify a condition or tell the database how to handle the data. It helps you filter and organise the results based on what you need. Common examples include WHERE, HAVING, ORDER BY, LIMIT, LIKE, AND, and OR.

What are some common clauses used with the SELECT query?

Some commonly used clauses with the SELECT statement are:

  • FROM
  • JOIN
  • WHERE
  • GROUP BY
  • HAVING
  • ORDER BY
  • LIMIT

These clauses help you retrieve and organise data from one or more tables.

How do you create a table in SQL?

You can create a new table in SQL using the CREATE TABLE statement. It allows you to define the table name and specify the columns and their data types.

How do you update a table?

The UPDATE statement changes existing values in a table. You can specify the columns and new values using SET and use WHERE to choose the records you want to update.

How do you delete a table from a database?

The DROP TABLE statement permanently removes a table and its data from a database.

How do you count the records in a table?

You can use the COUNT() function with * to find the total number of records in a table.

How do you sort records in a table?

You can use the ORDER BY clause to sort records based on one or more columns. By default, results are sorted in ascending order. Use DESC for descending order.

How do you select all columns from a table?

The asterisk (*) is used with the SELECT statement to retrieve all columns available in a table.

How do you select common records from two tables?

The INTERSECT operator returns rows present in both queries. The queries must return the same number of columns with compatible data types.

What is the DISTINCT statement, and how do you use it?

The DISTINCT keyword shows unique values in the query result. It removes duplicate records from the selected results and is commonly used with SELECT.

What are relationships? Give some examples.

Relationships define how two or more tables in a database are connected. They link related information across tables. For example, a customer ID can link customer details to that customer’s sales records.

What is a NULL value? How is it different from zero or a blank space?

NULL represents a missing, unknown, or unavailable value. It differs from zero, which is a numeric value, and from an empty string, which is a valid string with no characters.

How does SQL differ from NoSQL? 

SQL is mainly used with relational databases, where data is organised into tables with a defined structure. NoSQL databases use more flexible ways to store data and are often used for unstructured or semi-structured information.

What is a database snapshot, and how is it used?

A database snapshot is a read-only version of a database captured at a specific time. It helps you look at the database in its previous state without affecting the original data. It can be useful for reporting, testing, or checking changes made to the database. 

What are some common challenges when working with SQL databases?

Common challenges include handling large datasets, improving query performance, choosing the right indexes, maintaining data integrity, managing concurrent transactions, and optimising queries for scalability.

Database professionals also need to consider data security, backup and recovery, and efficient database design when working with larger systems.

What is a Common Table Expression (CTE)?

A Common Table Expression (CTE) is a temporary result set that is given a name and used within a SQL query to make complex queries easier to understand and manage. You define it with the WITH keyword, which makes complex queries easier to read, organise, and manage.

What are window functions, and how do they differ from aggregate functions?

Window functions perform calculations across a group of related rows while keeping each row separate in the result. They use the OVER() clause to define the rows included in the calculation. Unlike aggregate functions, they do not combine multiple rows into a single result.

What is a function in SQL?

A database object that defines a group of SQL statements often used for a certain task. A function takes in some input parameters, performs calculations or other manipulations on them, and returns the result. Functions improve code readability and avoid repeating the same code snippets.

What types of SQL functions do you know?

There are two common types of SQL functions: aggregate functions and scalar functions. Aggregate functions perform calculations on a group of rows and return one result, while scalar functions work on individual values and return a result for each row. Functions can also be built into the database or created by users when needed.

What are case manipulation functions in SQL?

Case manipulation functions change how text is written. They can convert text to uppercase, lowercase, or title case, making it easier to format and standardise text data in a database.

How does SQL differ from PL/SQL? 

SQL retrieves, inserts, updates, and manages data in relational databases. PL/SQL is an extension of SQL used in Oracle databases that adds programming features such as loops, conditions, and exception handling, making it suitable for handling more complex database logic.

Is there any difference between LEFT JOIN and LEFT OUTER JOIN

There is no major difference between LEFT JOIN and LEFT OUTER JOIN. Both work the same way and return all records from the left table, along with matching records from the right table. The OUTER keyword is optional.

What is indexing in SQL, and how does it improve performance?

Indexing makes data searches faster in a database. It creates a separate structure that helps the database locate the required rows without checking every record in the table. However, too many indexes can slow INSERT, UPDATE, and DELETE operations because the database must maintain them.

What is a stored procedure, and how is it different from a function?

A stored procedure is a group of SQL statements stored in the database that can be executed to perform a particular task. It can perform operations such as modifying data or managing transactions. A function is generally created to perform a specific calculation or operation and return a value.

How do you differentiate between a primary key and a unique key in SQL?

Both primary keys and unique keys prevent duplicate values. A primary key uniquely recognises each record in a table, while a unique key ensures the values in a column remain unique.

What is a view in SQL?

A view is a virtual table created from data in one or more database tables. It simplifies complex queries and can show only the required data without storing a separate copy.

Can we create a view based on another view in SQL?

Yes, you can create a view using another view. This is called a nested view. However, using too many nested views can make queries harder to understand and maintain.

Can we still use a view if the original table is deleted?

Generally, no. If a view depends on a deleted table, the view may become invalid because its underlying data source is no longer available.

What values can a BOOLEAN data field store? 

A BOOLEAN field is used to represent true or false values. Depending on the SQL database, it may support TRUE, FALSE, and NULL. Some databases, such as SQL Server, use the BIT data type, where 1 represents true, and 0 represents false.

What are the differences between isolation levels in SQL?

Isolation levels determine how much one transaction can see the changes made by another transaction. The main levels are:

  • READ UNCOMMITTED: A transaction can read changes that have not been committed yet.
  • READ COMMITTED: A transaction can read only data that has already been committed.
  • REPEATABLE READ: Ensures that data read during a transaction stays consistent.
  • SERIALIZABLE: Provides the highest isolation by making transactions work as if they are running one after another.

What is normalisation in SQL?

Normalisation is the technique of organising data in a database to reduce duplicates and avoid inconsistencies. It helps keep data organised, accurate, and easier to maintain.

What is denormalisation in SQL?

Denormalisation is the process of intentionally adding some duplicate data or combining information from multiple tables. It can enhance query performance by reducing the need for complex joins, especially when data is read frequently.

What is the difference between renaming a column and giving an alias to it?

Renaming a column permanently changes its name in the database table. An alias gives a column a temporary name only for a particular query, usually to make the result easier to understand.

How are nested subqueries different from correlated subqueries?

A nested subquery is a query placed inside another query and can usually run independently. A correlated subquery relies on the outer query because it uses values from the outer query while executing.

How do you differentiate between clustered and non-clustered indexes?

A clustered index determines how the data is physically organised in a table, while a non-clustered index is stored separately from the actual data and points to the required records. A table can generally have only one clustered index but can have multiple non-clustered indexes.

What is the CASE function?

The CASE function applies if-then-else logic in SQL. It checks the conditions given in the WHEN clauses one by one and returns the value from the THEN clause when a condition is met. If none of the conditions matches, it returns the value in the ELSE clause, or NULL if no ELSE clause is provided.

How do RANK(), DENSE_RANK(), and ROW_NUMBER() differ in SQL?

These SQL window functions assign numbers or rankings to rows.

  • ROW_NUMBER() gives each row a unique sequential number, even when values are the same.
  • RANK() gives the same rank to tied values but skips the next rank. For example: 1, 2, 2, 4.
  • DENSE_RANK() also gives the same rank to tied values but does not skip any rank. For example: 1, 2, 2, 3.

How do you calculate a running total in SQL?

You can calculate a running total by using SUM() as a window function with OVER() and ORDER BY to determine the order in which values are added. It adds the values progressively based on the specified order.

What is the difference between the DELETE and TRUNCATE statements?

DELETE removes selected rows from a table and can use a WHERE condition. TRUNCATE removes all rows from a table while keeping the table structure. Their behaviour regarding transactions and rollback can vary between database systems.

What is the difference between the DROP and TRUNCATE statements?

DROP removes the entire table, including its structure and data. TRUNCATE removes all the data from a table but keeps the table structure so it can still be used.

What is the difference between the HAVING and WHERE statements?

WHERE filters individual rows before they are grouped, while HAVING filters groups after aggregation. When you use both, WHERE comes before GROUP BY, followed by HAVING.

How do you add a record to a table?

You can add a new record to a table using the INSERT INTO statement along with VALUES.

How do you delete a record from a table?

You can remove a record using the DELETE statement with a WHERE condition. You can also delete multiple records if they meet the given condition.

How do you add a column to a table?

You can create an extra column in an existing table by using ALTER TABLE together with ADD.

How do you rename a column in a table?

You can delete a column from a table using the ALTER TABLE statement with DROP COLUMN.

How do you delete a column from a table?

You can remove a column from a table using the ALTER TABLE statement with DROP COLUMN.

How can you find even and odd records in a table? 

You can check whether a number is even or odd by finding the remainder after dividing it by 2. You can use MOD() or the % operator, depending on the SQL database. If the remainder is 0, the value is even; otherwise, it is odd.

How do you avoid duplicate records when making a query?

You can use DISTINCT with SELECT to return unique records. You can also use a unique key to prevent duplicate values from being stored in a table.

How do you insert many rows into a table?

You can insert multiple records at once using the INSERT INTO statement with multiple sets of values.

How do you find the nth highest value in a column?

You can use a window function such as DENSE_RANK() to rank values in descending order, then select the required rank. This approach also handles duplicate values correctly.

How do you find values in a text column that start with a certain letter?

You can use the LIKE operator with the % wildcard. For example, LIKE ‘A%’ finds all values that start with the letter A.

How do you find the last ID in a table?

You can use the MAX() function to identify the highest ID in a table. Another option is to sort the IDs in descending order and select the first record.

How do you select random rows from a table?

You can use a random function such as RAND() or RANDOM(), depending on the SQL database, along with ORDER BY and LIMIT to retrieve random records.

What is a materialised view?

A materialised view stores a query’s result as physical data in the database. Unlike a regular view, it does not run the query every time you access it. This can speed up data retrieval, especially for complex queries, large joins, and summary reports.

How do OLTP and OLAP systems differ?

OLTP systems are designed to handle day-to-day transactions such as inserting, updating, and retrieving records quickly. OLAP systems are mainly used to analyse large amounts of data, run complex queries, and generate reports for decision-making.

What is a deadlock, and how do you prevent it?

A deadlock occurs when two or more transactions wait for each other to release locks, so neither can continue.

For example, one transaction may lock Table X while waiting for Table Y, while another locks Table Y and waits for Table X.

Deadlocks can be prevented by:

  • Using a consistent lock order across transactions.
  • Keeping transactions short and completing them quickly.
  • Using suitable isolation levels to reduce lock contention.
  • Locking only the data that is needed.
  • Retrying transactions when a deadlock occurs, as many databases can detect and resolve deadlocks automatically.

What are ACID properties in database transactions?

ACID properties ensure database transactions work reliably and data remains accurate. The four properties are:

  • Atomicity: Assures that all operations in a transaction happen together or none of them happens.
  • Consistency: Ensures the transaction does not break the database’s rules or constraints.
  • Isolation: Ensures that one transaction does not affect another transaction running at the same time.
  • Durability: Ensures that committed changes are retained even after a system failure.

Conclusion

Preparing for a SQL interview is not just about memorising definitions. You need to understand how SQL works and apply it to real data. The questions covered in this guide range from basic SQL concepts to joins, subqueries, indexes, window functions, and practical SQL problems.

If you are preparing for your first job or planning to move into data analytics, regular practice can make a big difference. Try writing queries on real datasets and solving different types of problems to improve your skills.

If you want to build stronger skills in SQL along with other data analytics tools, a data analyst course in Kochi can give you structured learning and practical experience.

Use these questions as a starting point, keep practising, and focus on understanding the logic behind each query rather than simply memorising the answers.

Author Info

CA Veena Vijayan

CA Veena Vijayan

Ms. Veena Vijayan is a Chartered Accountant with over 15 years of hands-on experience in finance, accounting, taxation, audit, and compliance across different industries. Throughout her career, she has taken on key responsibilities from managing finance and accounts departments to working as an Audit Manager and later becoming an Audit Partner. As the Chief Executive Officer at Finprov, Ms. Veena focuses on building efficient systems, strengthening teams, and ensuring smooth execution across departments. She also plays a key role in improving learning and training experiences while supporting the company’s long-term goals and annual business strategies. Her thoughtful leadership and commitment to continuous improvement contribute significantly to Finprov’s growth, innovation, and overall development.

Latest Post