0% found this document useful (0 votes)
2 views10 pages

SQL Questions

The document outlines various SQL interview questions categorized into basic, intermediate, advanced, and scenario-based questions. It covers fundamental concepts such as SQL statements, joins, normalization, indexes, and ACID properties, as well as practical SQL queries for specific scenarios. This resource serves as a comprehensive guide for preparing for SQL interviews.

Uploaded by

praveentalend8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views10 pages

SQL Questions

The document outlines various SQL interview questions categorized into basic, intermediate, advanced, and scenario-based questions. It covers fundamental concepts such as SQL statements, joins, normalization, indexes, and ACID properties, as well as practical SQL queries for specific scenarios. This resource serves as a comprehensive guide for preparing for SQL interviews.

Uploaded by

praveentalend8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

SQL MOST IMP

interview questions

✅**Basic SQL Interview


Questions**
✅**Intermediate SQL
Questions**
✅**Advanced SQL
Questions**
✅**Scenario-Based SQL
Questions**
### 🔹 **Basic SQL Interview Questions**
1. **What is SQL?**

* SQL (Structured Query Language) is used to


communicate with relational databases for
storing, manipulating, and retrieving data.

2. **What are the different types of SQL


statements?**

* DDL (Data Definition Language): `CREATE`,


`ALTER`, `DROP`
* DML (Data Manipulation Language):
`SELECT`, `INSERT`, `UPDATE`, `DELETE`
* DCL (Data Control Language): `GRANT`,
`REVOKE`
* TCL (Transaction Control Language):
`COMMIT`, `ROLLBACK`, `SAVEPOINT`
3. **What is the difference between
`WHERE` and `HAVING`?**

* `WHERE` filters rows before grouping,


`HAVING` filters after `GROUP BY`.

4. **What is a Primary Key?**

* A field (or combination) that uniquely


identifies each record in a table.

5. **What is the difference between `INNER


JOIN`, `LEFT JOIN`, and `RIGHT JOIN`?**

* `INNER JOIN`: Only matching rows


* `LEFT JOIN`: All from left, matching from
right
* `RIGHT JOIN`: All from right, matching
from left
### 🔹 **Intermediate SQL Questions**
6. **What is normalization?**

* Process of organizing data to reduce


redundancy and improve integrity (1NF, 2NF,
3NF, etc.).

7. **What are indexes? Why are they used?**

* Indexes improve query speed by allowing


faster data retrieval, but they can slow down
write operations.

8. **What is the difference between `DELETE`,


`TRUNCATE`, and `DROP`?**

* `DELETE`: Removes specific rows (can be


rolled back)
* `TRUNCATE`: Removes all rows, can't be
rolled back
* `DROP`: Deletes the table structure
9. **What is a foreign key?**

* A key used to link two


tables, enforcing referential
integrity.

10. **What is a subquery?**

* A query nested inside


another query.
### 🔹 **Advanced SQL
Questions**

11. **What is a `CROSS


JOIN`?**

* Produces a Cartesian
product of two tables.

12. **What is a window


function?**

* Functions like
`ROW_NUMBER()`, `RANK()`,
`LEAD()`, `LAG()` used over
partitions of data.
13. **What is the difference between
`UNION` and `UNION ALL`?**

* `UNION`: Removes duplicates


* `UNION ALL`: Includes duplicates

14. **What is the difference between


`EXISTS` and `IN`?**

* `EXISTS` is used for correlated


subqueries; more efficient in large
datasets compared to `IN`.

15. **What are ACID properties?**

* Atomicity, Consistency, Isolation,


Durability – they guarantee reliable
database transactions.
### 🔹 **Scenario-Based
SQL Questions**

16. **How do you find the


second highest salary from
a table?**

```sql
SELECT MAX(salary)
FROM employees
WHERE salary < (SELECT
MAX(salary) FROM
employees);
```
17. **How do you retrieve duplicate
rows in a table?**

```sql
SELECT column_name, COUNT(*)
FROM table_name
GROUP BY column_name
HAVING COUNT(*) > 1;
```

18. **How can you get the top N


records?**

```sql
SELECT * FROM table_name ORDER
BY column_name DESC LIMIT N;
```
19. **How to find rows that exist in one table but
not in another?**
```sql
SELECT *
FROM table1
WHERE NOT EXISTS (
SELECT 1 FROM table2 WHERE table1.id =
table2.id
);
```
20. **What is a Common Table Expression (CTE)?
**
* A temporary result set that can be referred
within `SELECT`, `INSERT`, `UPDATE`, or
`DELETE` statements.
```sql
WITH cte_name AS (
SELECT ...
)
SELECT * FROM cte_name;
```

You might also like