0% found this document useful (0 votes)
8 views4 pages

SQL Practise Questions

The document outlines a series of SQL query exercises divided into five sections: Basic SQL Queries, JOINS & Relationships, Aggregates & Grouping, Subqueries & Filtering, and Window Functions & Advanced. Each section contains a set of questions that focus on specific SQL concepts and operations, providing example queries for practice. The exercises cover a range of topics including SELECT statements, JOIN operations, aggregation functions, and window functions.

Uploaded by

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

SQL Practise Questions

The document outlines a series of SQL query exercises divided into five sections: Basic SQL Queries, JOINS & Relationships, Aggregates & Grouping, Subqueries & Filtering, and Window Functions & Advanced. Each section contains a set of questions that focus on specific SQL concepts and operations, providing example queries for practice. The exercises cover a range of topics including SELECT statements, JOIN operations, aggregation functions, and window functions.

Uploaded by

Aman Ahmed Khan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

🔰 SECTION 1: Basic SQL Queries (Easy – 15

Questions)
Focus: SELECT, WHERE, ORDER BY, DISTINCT, LIMIT, IS NULL, IN, BETWEEN

1. Select all columns from a table named employees.

SELECT * from employees;

2. Select the names of all employees who work in the “HR” department.

SELECT name_emp from employees


where department_name = ‘HR’

3. Retrieve a list of unique cities from the customers table.

SELECT DISTINCT (city) from customers

4. Get all products priced between 100 and 500.

SELECT * from orders


where price is between 100 and 500;

5. List all customers who are from "Indore" or "Delhi".

Select customer_name from customers


where city in ("Indore" or "Delhi")

6. Find all employees who do not have a manager assigned (manager_id IS NULL).
Select * from employees
where manager_id is Null;

7. Select the top 5 highest-paid employees.

SELECT *

From employees

Order by salary desc

Limt 5;

8. Sort the list of products by price in descending order.

SELECT Product ,price


FROM products
order BY price desc;

9. Find the oldest employee from the employees table.


Select * from employees
order by desc
limit 1 ;

10. List all customers who joined in the year 2022.

Select * from customers


where year = 2022;

11. Retrieve all orders placed in the last 7 days.

SELECT * from order


where date >= current_date– interval 7 days

12. Get the names of employees whose names start with 'A'.

Is like “%A”

13. List all products that have "eco" in their name.

Is like “%eco”

14. Count the number of unique countries in the customers table.

Select Distinct count(country) from customer

15. Display the first 10 rows from the orders table.

🔄 SECTION 2: JOINS & Relationships (Moderate – 10 Questions)

Focus: INNER JOIN, LEFT JOIN, RIGHT JOIN, SELF JOIN

16. Join orders and customers to get customer names along with their orders.

Select t1.customer_name,[Link]
from customers t1

Join orders t2

On t1.customer_id = t2.customer_id;

17. List all products and their suppliers using a join.

Select [Link],t2.Suppliers_name

From products t1
join suppliers t2
on [Link]=[Link];

Find all customers who haven’t placed any orders.


Select t1.customer_id,t2.order_id
From products t1
left join orders t2
on [Link]=[Link]
Where t2.order_id IS NULL;

18. Get a list of employees along with their managers’ names (self join).

19. Join employees with departments and show employee name + department name.

20. List all employees along with department info, including those without a department.

21. Get all transactions along with product names (using join).

22. Find orders placed by customers from “Mumbai”.

23. List all employees and the name of the department they belong to.

24. Get the number of orders each customer has placed (grouped join).

📊 SECTION 3: Aggregates & Grouping (Moderate – 10 Questions)

Focus: GROUP BY, HAVING, COUNT(), SUM(), AVG(), MIN(), MAX()

26. Count the number of orders placed by each customer.

27. Find the total sales (sum of amount) by each product.

28. Get the average salary by department.

29. List departments with more than 10 employees.

30. Find the highest order value for each customer.

31. Count how many employees joined each year.

32. Find products that have never been ordered.

33. Show the minimum, maximum, and average salary in the company.

34. List the top 3 customers who spent the most.

35. Get the count of orders per status (e.g., Delivered, Cancelled).

🧠 SECTION 4: Subqueries & Filtering (Medium – 10 Questions)

Focus: Scalar & Correlated Subqueries, Nested Filtering

36. Find customers who placed more orders than the average number of orders.

37. List employees who earn more than their department’s average salary.

38. Show products whose price is greater than the average product price.
39. Get the customer who placed the largest order.

40. Retrieve products that were never ordered using a subquery.

41. List customers who have ordered every product (use COUNT DISTINCT).

42. Find the second highest salary in the employees table.

43. Find the products with the least sales quantity.

44. List departments where no employee earns more than ₹50,000.

45. Display employees who joined before their manager.

🪟 SECTION 5: Window Functions & Advanced (Medium – 5 Questions)

Focus: ROW_NUMBER(), RANK(), LAG(), LEAD(), PARTITION BY

46. Assign row numbers to each order, ordered by date for each customer.

47. Rank employees by salary within each department.

48. Find the top 2 selling products in each category.

49. Compare each order’s value to the previous order by the same customer.

50. Calculate running total (cumulative sum) of sales per cu

You might also like