Question 1 Report
A shop database has a table called Products with the following data.
| ProductID | Name | Category | Price | StockLevel |
|---|---|---|---|---|
| 1 | Keyboard | Peripherals | 25.99 | 45 |
| 2 | Mouse | Peripherals | 12.50 | 120 |
| 3 | Monitor | Display | 199.99 | 15 |
| 4 | USB Cable | Accessories | 5.99 | 200 |
| 5 | Headset | Peripherals | 34.99 | 30 |
(a) Write an SQL query to display the Name and Price of all products in the Peripherals category.
[3]
(b) Write an SQL query to find all products where the StockLevel is less than 50.
[2]
(c) Write an SQL query to display all products ordered by Price from highest to lowest.
[2]
This question tests your ability to write SQL queries to retrieve specific data from a database table. [7]
(a) SQL query to display the Name and Price of all Peripherals products: [3]
SELECT Name, Price
FROM Products
WHERE Category = 'Peripherals'This query works as follows:
The query would return:
| Name | Price |
|---|---|
| Keyboard | 25.99 |
| Mouse | 12.50 |
| Headset | 34.99 |
(b) SQL query to find all products with StockLevel less than 50: [2]
SELECT * FROM Products
WHERE StockLevel < 50SELECT * retrieves all columns. The WHERE StockLevel < 50 condition filters to show only products with stock below 50 units. [1] This would return Keyboard (45), Monitor (15), and Headset (30). [1]
(c) SQL query to display all products ordered by Price from highest to lowest: [2]
SELECT * FROM Products
ORDER BY Price DESCORDER BY Price sorts the results by the Price column. [1] DESC specifies descending order (highest to lowest). Without DESC, the default would be ascending (lowest to highest). [1] The results would appear in this order: Monitor (199.99), Headset (34.99), Keyboard (25.99), Mouse (12.50), USB Cable (5.99).
Everything you need to excel in your exams