Excellent idea!
Let's create a comprehensive practice question list that covers all the major query
types and clauses from the SQL cheat sheet.
Practice Questions (Covering Cheat Sheet Topics):
1. Basic SELECT and Filtering:
Question: Retrieve all columns and rows from the Customers table.
Question: Retrieve only the customer_name and city columns from the Customers table.
Question: Retrieve distinct city values from the Customers table.
Question: Find all products with a price exactly equal to $150.
Question: Find all orders with total_amount greater than 200.
Question: Find all products with names that start with 'L'.
Question: Find all customers whose customer_id is 1, 3, or 5.
Question: Find all orders placed between '2023-06-01' and '2023-08-31'.
Question: Find all customers with a city that is NULL.
Question: Find all customers with a city that is NOT NULL.
2. Logical Operators:
Question: Find all customers from 'London' AND with an email address.
Question: Find all customers from 'New York' OR 'Paris'.
Question: Find all products that are NOT in the 'Books' category.
3. ORDER BY and LIMIT/OFFSET:
Question: Retrieve all products, ordered by price in ascending order.
Question: Retrieve all orders, ordered by order_date in descending order.
Question: Retrieve the top 3 most expensive products.
Question: Retrieve the 4th to 6th orders (using OFFSET and LIMIT).
4. Aggregate Functions:
Question: Count the total number of customers.
Question: Calculate the sum of all order total_amount values.
Question: Calculate the average price of all products.
Question: Find the minimum and maximum price of products.
5. GROUP BY and HAVING:
Question: Count the number of orders placed by each customer.
Question: Find the average price of products in each category.
Question: Find the categories that have more than 2 products.
Question: Find customers who have placed more than 1 order.
6. JOINs:
Question: Retrieve the order_id and customer_name for all orders. (INNER JOIN)
Question: Retrieve all customers and their orders, including customers who have not placed
orders. (LEFT JOIN)
Question: Retrieve all orders and their customers, including orders that have no matching
customer. (RIGHT JOIN)
Question: Retrieve all customers and all orders, including those that don't match. (FULL
OUTER JOIN)
Question: Create a cartesian product of customers and products.
7. INSERT, UPDATE, and DELETE:
Question: Insert a new product into the Products table.
Question: Update the price of a specific product.
Question: Delete a specific customer from the Customers table.
8. CREATE TABLE, ALTER TABLE, and DROP TABLE:
Question: Create a new table called Employee with columns employee_id, employee_name,
and department.
Question: Add a new column phone_number to the Customers table.
Question: Drop the Employee table.
Question: Change the data type of the price column to a larger decimal.
Question: Rename the customer name column to full_name.
Question: Add a constraint to the customer table, to make sure that the email column is
unique.
9. CREATE INDEX and DROP INDEX:
Question: Create an index on the customer_id column in the Orders table.
Question: Drop the index created in the previous question.
10. CREATE VIEW and DROP VIEW:
Question: Create a view that shows the customer_name and the total number of orders for
each customer.
Question: Drop the view created in the previous question.
12. GRANT/REVOKE:
Question: Grant SELECT permission on the Products table to a user named 'testuser'.
Question: Revoke SELECT permission on the Products table from the user 'testuser'.
Basic Retrieval and Filtering:
1. Question: Retrieve the names and cities of all customers.
2. Question: Find all products with a price greater than $50.
3. Question: List all orders placed on or after '2023-06-01'.
4. Question: Retrieve the email addresses of customers living in 'London'.
5. Question: Find all products in the 'Clothing' category.
6. Question: Retrieve orders with total amounts between $100 and $500.
7. Question: Find customer names that contain the letter 'a'.
8. Question: Find all products that are not in the 'Electronics' category.
9. Question: Retrieve all orders from customer id 1, or customer id 2.
Joins and Relationships:
10. Question: List the order IDs and customer names for all orders.
11. Question: Retrieve the product names and order dates for all products that were ordered.
12. Question: Show the customer names and the total amounts they have spent.
13. Question: Find the customer names and the products they have ordered.
14. Question: Find the customer names and order dates for all customers who have placed an
order.
15. Question: Show all customers and their orders, even if the customer has not placed any
orders.
Aggregate Functions and Grouping:
16. Question: Calculate the total number of customers.
17. Question: Find the average price of all products.
18. Question: Calculate the total amount of all orders.
19. Question: Find the highest and lowest order amounts.
20. Question: Count the number of orders placed by each customer.
21. Question: Find the total amount spent by each customer, ordered from highest to lowest.
22. Question: Find the average price of products in each category.
23. Question: Show the categories that have more than 5 products.
24. Question: Show the customer names that have placed more than 2 orders.
Subqueries and Advanced Queries:
25. Question: Find the products with prices higher than the average price of all products.
26. Question: Retrieve the customers who have placed orders with amounts greater than the
average order amount.
27. Question: Find the customers who have placed orders for all products in the 'Books'
category.
28. Question: Find the customer who has spent the most money.
29. Question: Create a view that shows the customer names and their total order amounts.
30. Question: Find the products that have never been ordered.
31. Question: Find the customers who have not placed any orders.
32. Question: Find the customer who has placed the most orders.
Data Manipulation:
33. Question: Insert a new product into the Products table.
34. Question: Update the price of a product.
35. Question: Delete a customer from the Customers table.
36. Question: Add a new column to the Customers table for phone numbers.
37. Question: Change the data type of the price column in the Products table.
38. Question: Create an index on the customer_id column in the Orders table.