0% found this document useful (0 votes)
79 views3 pages

Here’s a list of 100 SQL questions

The document contains a comprehensive list of 100 SQL questions categorized into DML, DDL, JOINS, SUBQUERIES, and mixed concepts. It serves as a practice resource for individuals looking to enhance their SQL skills, covering a range of topics from basic data manipulation to advanced querying techniques. Each category includes specific tasks to help users apply their knowledge effectively.

Uploaded by

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

Here’s a list of 100 SQL questions

The document contains a comprehensive list of 100 SQL questions categorized into DML, DDL, JOINS, SUBQUERIES, and mixed concepts. It serves as a practice resource for individuals looking to enhance their SQL skills, covering a range of topics from basic data manipulation to advanced querying techniques. Each category includes specific tasks to help users apply their knowledge effectively.

Uploaded by

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

Here’s a list of **100 SQL questions** organized into categories including **DML

(Data Manipulation Language)**, **DDL (Data Definition Language)**, **JOINS**, and


**SUBQUERIES** to help you practice.

---

### **DML (Data Manipulation Language) Questions**


1. Insert a new record into the `employees` table.
2. Update the salary of an employee whose ID is 101.
3. Delete a record from the `departments` table where `department_id = 10`.
4. Retrieve all rows from the `products` table.
5. Select specific columns (`name` and `price`) from the `products` table.
6. Add 10% to all employees’ salaries.
7. Delete all rows from the `orders` table.
8. Insert multiple records into the `customers` table.
9. Retrieve distinct values from the `categories` column of the `products` table.
10. Sort the results of the `employees` table by their `hire_date`.
11. Retrieve rows where the `price` of products is greater than 500.
12. Select employees whose name starts with the letter ‘A’.
13. Retrieve products priced between 100 and 500.
14. Select customers whose email ends with "@gmail.com".
15. Retrieve rows where the `quantity` is NULL.
16. Insert a default value for a `status` column in the `orders` table.
17. Update multiple rows based on a condition in the `students` table.
18. Replace all NULL values in the `phone_number` column with "N/A".
19. Delete rows where `rating` is less than 3 from the `reviews` table.
20. Insert a record into the `sales` table, including the current date and time.

---

### **DDL (Data Definition Language) Questions**


21. Create a new table named `users` with columns `id`, `name`, and `email`.
22. Alter the `employees` table to add a column `age`.
23. Drop the `temp_data` table.
24. Rename the `orders` table to `customer_orders`.
25. Modify the `salary` column of the `employees` table to increase its size.
26. Create a table with a `PRIMARY KEY` constraint.
27. Add a `UNIQUE` constraint to the `email` column of the `users` table.
28. Drop a column `age` from the `students` table.
29. Create a table with a `FOREIGN KEY` constraint.
30. Create a table with a `CHECK` constraint to ensure `age` is greater than 18.
31. Create an index on the `name` column of the `products` table.
32. Drop an index from the `categories` table.
33. Create a table with a `DEFAULT` constraint for a column.
34. Drop a `FOREIGN KEY` constraint from the `orders` table.
35. Add a `NOT NULL` constraint to the `email` column in the `users` table.
36. Create a new schema named `sales_data`.
37. Alter the `products` table to change the data type of `price` from INT to
DECIMAL.
38. Drop a `CHECK` constraint from the `students` table.
39. Create a table that stores only unique email addresses.
40. Write a query to truncate all data from the `logs` table.

---

### **JOINS Questions**


41. Retrieve all employees along with their department names using an `INNER JOIN`.
42. List all customers and their orders, including those without orders, using a
`LEFT JOIN`.
43. Retrieve all orders and their associated customers using a `RIGHT JOIN`.
44. Get a list of products and categories using an `INNER JOIN`.
45. Combine two tables `employees` and `managers` to find matching records using an
`INNER JOIN`.
46. List all students and their grades, even if grades are missing, using a `LEFT
JOIN`.
47. Retrieve rows from two tables where no match exists using a `FULL OUTER JOIN`.
48. Join three tables (`orders`, `customers`, and `products`) to retrieve order
details.
49. List employees and their managers using a self-join.
50. Write a query to perform a `CROSS JOIN` between two tables.
51. Get all employees whose salary is greater than their department's average
salary using a `JOIN`.
52. Find customers who have placed orders and retrieve both customer and order
details.
53. Retrieve all products that do not belong to any category using a `LEFT JOIN`.
54. List all authors and their books, including those who have not written any
books.
55. Join the `students` table with the `courses` table to get course enrollments.
56. Write a query to find matching rows from two tables using `NATURAL JOIN`.
57. Retrieve all employees and their project details, including those not assigned
to any projects.
58. Find all customers who have purchased a specific product using a join.
59. Combine `products` and `sales` tables to calculate total revenue for each
product.
60. Write a query to join two tables and filter the results based on conditions.

---

### **Subqueries Questions**


61. Retrieve employees with a salary higher than the average salary.
62. Find the names of customers who have placed orders in the last 7 days.
63. Get the product details of the most expensive product using a subquery.
64. List all employees who work in the same department as "John".
65. Retrieve the second-highest salary from the `employees` table.
66. Find all products with prices above the average price.
67. Get all orders where the customer has a balance greater than $500.
68. Find employees whose `id` exists in the `managers` table using a subquery.
69. Retrieve the names of employees who do not belong to any department.
70. List customers who have not placed any orders using a subquery.
71. Get the top 3 highest-paid employees using a subquery.
72. Write a query to delete all rows where a matching ID exists in another table.
73. Find all students enrolled in courses offered in the "Fall" semester.
74. Write a query to insert a row only if a certain condition is met using a
subquery.
75. Get the details of products sold by the top 3 sellers.
76. Retrieve orders placed in the same month as the highest revenue order.
77. Find all customers whose total purchase amount exceeds $1000 using a subquery.
78. List employees with a higher salary than the department average salary using a
subquery.
79. Retrieve the names of authors who have published more than 5 books.
80. Get all products that are cheaper than the average price of products in the
same category.

---

### **Mixed Questions (Combining Concepts)**


81. Write a query to create a new table with a foreign key and insert data into it.
82. Find the total sales for each category using joins and group by.
83. Get all employees who joined before the average hire date of their department.
84. Retrieve customers who placed the most recent orders using a subquery.
85. Update salaries of employees who have a specific skill using joins.
86. Write a query to join three tables and include filtering conditions on each
table.
87. Create a table, insert sample data, and query it using a subquery.
88. Find all students enrolled in a specific course using joins and subqueries.
89. Retrieve all departments with their total number of employees using joins.
90. Write a query to delete rows based on a condition involving a join.
91. Combine two queries using a union to list all products and their suppliers.
92. Create a table with default values and insert rows without specifying the
default column.
93. Find all customers who purchased products costing more than the average price.
94. Write a query to retrieve all employees along with their managers using a self-
join.
95. Create a table with a foreign key and enforce referential integrity using DDL.
96. List employees and the number of projects they are working on using joins and
group by.
97. Write a query to get employees who have worked on more than one project using
joins.
98. Find the most popular product in each category using subqueries and joins.
99. Write a query to truncate a table and then re-insert specific rows using a
subquery.
100. Combine DDL, DML, and subqueries to create, insert, and retrieve data from a
database.

---

This set of questions covers the fundamentals and advanced use cases of SQL,
helping you build a solid foundation. Let me know if you'd like detailed answers or
examples for any of these questions!

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy