0% found this document useful (0 votes)
6 views5 pages

SQL Questions

The document outlines various SQL concepts across multiple chapters, including data manipulation (DDL, DML, TCL), data retrieval and filtering, aggregation and grouping, joins, intermediate logic, advanced analytics, and database optimization. It poses questions and provides queries related to these topics, such as differences between SQL commands, examples of data retrieval, and the importance of database constraints. Additionally, it addresses advanced topics like window functions, indexing, normalization, and schema design.

Uploaded by

Pradeep Bodduru
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)
6 views5 pages

SQL Questions

The document outlines various SQL concepts across multiple chapters, including data manipulation (DDL, DML, TCL), data retrieval and filtering, aggregation and grouping, joins, intermediate logic, advanced analytics, and database optimization. It poses questions and provides queries related to these topics, such as differences between SQL commands, examples of data retrieval, and the importance of database constraints. Additionally, it addresses advanced topics like window functions, indexing, normalization, and schema design.

Uploaded by

Pradeep Bodduru
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

Chapter 1: The Foundation (DDL, DML, TCL, Constraints)

1.​ What is the difference between DROP, TRUNCATE, and DELETE?

2.​ What happens if you execute DROP TABLE by mistake? Can you
recover the table?

3.​ Explain the difference between DML, DDL, DCL, and TCL with
examples.

4.​ When would you use COMMIT and ROLLBACK in a real‑world


scenario?

5.​ What is the importance of constraints like PRIMARY KEY, UNIQUE,


FOREIGN KEY, and NOT NULL?

6.​ What is the difference between CHAR and VARCHAR? When should
each be used?

7.​ What happens if you try to insert a NULL value into a NOT NULL
column?

Chapter 2: Data Retrieval & Filtering (SELECT, WHERE,


DISTINCT, LIKE, ORDER BY)

1.​ Write a query to fetch all customers whose names start with ‘A’.

2.​ How do you remove duplicate rows from a result set? Show with
DISTINCT and an alternative without it.

3.​ Write a query to fetch employees whose salary is between 30000 and
60000.

4.​ Write a query to find all employees whose email contains the word
gmail.

5.​ How would you display the top 10 highest‑paid employees?


6.​ How do you skip the first 20 rows and fetch the next 10 rows for
pagination?

7.​ What is the difference between AND and OR in a WHERE clause? Give
an example.

8.​ What is the difference between IN and BETWEEN? When would you
prefer one over the other?

Chapter 3: Aggregation & Grouping (SUM, AVG, COUNT,


GROUP BY, HAVING)

1.​ Write a query to find the total number of orders per month.

2.​ Write a query to find the average salary per department.

3.​ Write a query to find which department has the highest total salary.

4.​ What is the difference between WHERE and HAVING? When should
you use HAVING?

5.​ Write a query to count how many employees have a salary greater than
50000 in each department.

6.​ What happens if you use a column in SELECT that is not in GROUP BY
and not aggregated?

7.​ Write a query to find departments that have more than 5 employees.

Chapter 4: Joins & Set Operations (INNER, LEFT, RIGHT,


FULL, SELF, CROSS, UNION)

1.​ What is the difference between INNER JOIN and LEFT JOIN? Show
with an example.
2.​ Write a query to fetch all customers and their orders, even if they have
no orders.

3.​ How do you find customers who have never placed an order using
LEFT JOIN?

4.​ What is a SELF JOIN? Give an example using an employee‑manager


hierarchy.

5.​ Write a query to find employees who earn more than their managers.

6.​ What is the difference between UNION and UNION ALL? When should
you use each?

7.​ Write a query to combine customer data from two different regions into
one result set.

8.​ What is a CROSS JOIN? When would you use (or avoid) it?

Chapter 5: Intermediate Logic (Subqueries, CTEs, CASE)

1.​ What is a correlated subquery? Give an example.

2.​ Write a query to find employees who earn more than the average salary
using a subquery.

3.​ Write a query to find the second‑highest salary in the company.

4.​ How does a CTE (WITH) help in writing cleaner SQL? Show an
example.

5.​ Rewrite a complex nested query using a CTE.

6.​ Use a CASE statement to categorize employees as ‘Low’, ‘Medium’, or


‘High’ salary.

7.​ Write a query to show the number of orders per status (e.g., ‘Pending’,
‘Shipped’, ‘Delivered’) using CASE.
Chapter 6: Advanced Analytics (Window Functions: RANK,
DENSE_RANK, LEAD, LAG, Aggregate Windowing)

1.​ What is the difference between RANK() and DENSE_RANK()? Explain


with an example.
2.​ Write a query to rank employees by salary within each department.

3.​ Find the top 3 highest‑paid employees in each department using


ROW_NUMBER() or RANK().

4.​ What do LEAD() and LAG() do? Give an example for sales
month‑over‑month comparison.

5.​ Write a query to calculate a running total of sales for each month.

6.​ Write a query to show the difference between the current month’s sales
and the previous month’s sales.

7.​ How would you calculate the percentage of each department’s salary
compared to the total salary?

Chapter 7: Database Objects & Optimization (Indexes,


Views, Normalization, ACID)

1.​ What is an index? Why is it important for performance?

2.​ When should you avoid creating an index on a column?

3.​ What is the difference between a VIEW and a TABLE? Where would
you use a view?

4.​ What are Stored Procedures and User‑Defined Functions? Give a


simple example.

5.​ Explain ACID properties in your own words.

6.​ What does Normalization mean? Why is it important?


7.​ Explain the differences between 1NF, 2NF, and 3NF with simple
examples.

8.​ How would you optimize a slow‑running query that uses LIKE
'%keyword' on a large column?

9.​ What happens if you put an index on every column in a table? Is it good
or bad?

Bonus: “Tricky” / Frequency‑Based Questions (Very


Common in 2026)

1.​ What is the order of execution of an SQL query (FROM → WHERE →


GROUP BY → HAVING → SELECT → ORDER BY → LIMIT)?

2.​ What is the difference between NULL and an empty string? How does
NULL behave in arithmetic and comparisons?

3.​ How do you handle NULL values in GROUP BY and ORDER BY?

4.​ How do you prevent duplicate rows when inserting data from a file or
API?

5.​ How do you design a database schema for a simple e‑commerce


system (Customers, Orders, Products, Payments)?

6.​ Write a query to find the latest order for each customer.

7.​ How would you model a many‑to‑many relationship (e.g., Students and
Courses) in SQL?

You might also like