Most Asked SQL Interview Q&a
Most Asked SQL Interview Q&a
1. What is SQL?
Answer: SQL stands for Structured Query Language, and it is a domain-specific language used
for managing and manipulating relational databases.
2. What is a database?
Answer: A database is a structured collection of data that is organized and stored for efficient
retrieval and manipulation.
Answer: SQL is a language used to manage and manipulate relational databases, while MySQL
is an open-source relational database management system (RDBMS) that uses SQL as its
query language.
Answer: A primary key is a unique identifier for a record in a database table. It ensures that
each record can be uniquely identified and helps maintain data integrity.
Answer: A foreign key is a field in a database table that is used to establish a link between the
data in two tables. It creates a relationship between the tables by referencing the primary key
of another table.
Answer: SQL commands can be broadly categorized into Data Definition Language (DDL),
Data Manipulation Language (DML), Data Query Language (DQL), and Data Control Language
(DCL).
Answer: INNER JOIN returns only the rows where there is a match in both tables, while LEFT
JOIN returns all rows from the left table and the matched rows from the right table. If there is
no match, NULL values are returned for columns from the right table.
Answer: The GROUP BY clause is used to group rows that have the same values in specified
columns into summary rows, like finding the total or average for each group.
Answer: UNION combines the result sets of two queries, eliminating duplicate rows, while
UNION ALL combines the result sets including duplicates.
Answer: An index is a data structure that improves the speed of data retrieval operations on a
database table. It is used to quickly locate and access the ro in a table based on the values in
one or more columns.
Answer: A stored procedure is a precompiled collection of one or more SQL statements that
can be executed as a single unit. It is stored in the database and can be called by name.
Answer: ACID stands for Atomicity, Consistency, Isolation, and Durability. It is a set of
properties that guarantee that database transactions are processed reliably.
Answer: The HAVING clause is used in combination with the GROUP BY clause to filter the
results of a group based on a specified condition.
Answer: A view is a virtual table derived from one or more tables. It does not store the data
itself but provides a way to represent the result of a stored query.
17. Explain the difference between a clustered and a non- clustered index.
Answer: A clustered index determines the physical order of data in a table, whereas a non-
clustered index does not affect the physical order and creates a separate structure for faster
data retrieval.
Answer: The ORDER BY clause is used to sort the result set of a query in ascending or
descending order based on one or more columns.
20. Explain the difference between a candidate key, primary key, and a super key.
Answer: A super key is any set of columns that uniquely identifies a row, a candidate key is a
minimal super key, and the primary key is the chosen candidate key for a table.
Answer: The LIKE statement is used in a WHERE clause to search for a specified pattern in a
column.
Answer: A table is a physical storage structure that stores data, while a view is a virtual table
derived from one or more tables, presenting a way to represent the result of a stored query.
Answer: A self-join is a regular join, but the table is joined with itself. It is often used when a
table has a foreign key that references its own primary key.
Answer: The IN operator is used in a WHERE clause to filter the result set based on a specified
list of values.
Answer: A subquery is a query nested inside another query. It can be used to retrieve data
that will be used in the main query as a condition to further restrict the data to be retrieved.