Here Are Some Important SQL Interview Questions That Are Commonly Asked in Interviews
Here Are Some Important SQL Interview Questions That Are Commonly Asked in Interviews
1. What is SQL?
• Answer:
• Answer:
o INNER JOIN: Returns rows that have matching values in both tables.
o OUTER JOIN: Returns all rows from one table and the matching rows from the
other table. If no match exists, the result will include NULL values for non-
matching rows. Outer joins can be further classified as:
o 1NF (First Normal Form): Eliminate repeating groups; each column must
contain atomic values.
o 2NF (Second Normal Form): Meet 1NF and remove partial dependencies.
o 3NF (Third Normal Form): Meet 2NF and remove transitive dependencies.
• Answer:
o Primary Key: A unique identifier for each record in a table. A table can have
only one primary key, and it cannot have NULL values.
o Foreign Key: A column or group of columns in one table that refers to the
primary key in another table. It is used to establish a relationship between
two tables.
• Answer:
o DELETE: Removes rows from a table but does not remove the table structure.
It can be rolled back if used with a transaction.
o TRUNCATE: Removes all rows from a table and frees the space associated
with the table. It cannot be rolled back and does not log individual row
deletions.
• Answer: An index is a database object used to improve the speed of data retrieval
operations on a table. It creates a pointer to the data in a table, similar to the index
in a book. There are two types:
o Clustered Index: The data in the table is physically ordered based on the
index.
8. What is a subquery?
• Answer: A subquery is a query within another query. It is used to retrieve data that
will be used in the main query. Subqueries can be used in SELECT, INSERT, UPDATE,
and DELETE statements.
• Answer: The GROUP BY clause groups rows that have the same values in specified
columns into summary rows, like "count", "sum", "average". It is often used with
aggregate functions like COUNT(), SUM(), AVG(), MAX(), and MIN().
10. What are aggregate functions in SQL?
o COUNT()
o SUM()
o AVG()
o MIN()
o MAX()
• Answer:
o HAVING: Filters groups after the GROUP BY clause is applied (used with
aggregated results).
• Answer: The UNION operator is used to combine the result sets of two or more
SELECT statements. It removes duplicate rows by default. Use UNION ALL if you want
to include duplicates.
• Answer:
o UNION: Combines the results of two or more SELECT queries into one result
set, stacking rows vertically.
o JOIN: Combines columns from two or more tables based on a related column
between them, combining data horizontally.
• Answer: Constraints are used to enforce rules on data in a table. Common types of
constraints include:
o NOT NULL
o PRIMARY KEY
o FOREIGN KEY
o UNIQUE
o CHECK
o DEFAULT
• Answer: A VIEW is a virtual table that is based on the result of a SELECT query. It
does not store data physically but provides a way to access data from one or more
tables.
• Answer:
o CHAR: A fixed-length data type. If the string is shorter than the defined
length, it will be padded with spaces.
o Isolation: Ensures that transactions are isolated from each other, meaning
one transaction's operations are not visible to others until completed.
These questions cover fundamental SQL concepts and will give you a solid foundation for
interviews. Be prepared to explain your answers in depth and provide examples where
possible