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 Periph...

Assessment: Computer Science 0478 | Paper 1 Mock 01 | Computer Systems Subject: Computer Science - 0478

Question 1 Report

A shop database has a table called Products with the following data.

ProductIDNameCategoryPriceStockLevel
1KeyboardPeripherals25.9945
2MousePeripherals12.50120
3MonitorDisplay199.9915
4USB CableAccessories5.99200
5HeadsetPeripherals34.9930

(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]

Answer Details

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:

  • SELECT Name, Price specifies which columns to display in the results (only the product name and its price, not all columns). [1]
  • FROM Products identifies the table to query. [1]
  • WHERE Category = 'Peripherals' filters the results to include only rows where the Category field matches 'Peripherals'. [1]

The query would return:

NamePrice
Keyboard25.99
Mouse12.50
Headset34.99

(b) SQL query to find all products with StockLevel less than 50: [2]

SELECT * FROM Products
WHERE StockLevel < 50

SELECT * 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 DESC

ORDER 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).

Download The App On Google Playstore

Everything you need to excel in your exams

Green Bridge CBT Mobile App
Personalized AI Learning Chat Assistant
200,000+ Exam Questions Across IGCSE, JAMB, WAEC & NECO
Over 3,900 Lesson Notes
Offline Support - Learn Anytime, Anywhere
Green Bridge Timetable
Literature Summaries & Potential Questions
Track Your Performance & Progress
In-depth Explanations for Comprehensive Learning