Skip to content
IGCSE·Tuition
Computer Science · Practice

Databases and query reasoning: original mixed practice

Query questions reward slow, row-by-row checking, and this set is built to train exactly that habit.

These ten questions cover fields, records, keys, SELECT filters, Boolean grouping and empty results. They go from easy to harder. All use the same fictional Plants table, so no real personal data appears.

Write your own answer first, then open the worked solution. Test every query against all eight records, not only the likely ones.

PlantIDNameTypePriceStockIndoor
P01FernFoliage12.508TRUE
P02CactusSucculent6.0025TRUE
P03RoseFlowering15.000FALSE
P04MintHerb4.5040FALSE
P05OrchidFlowering28.003TRUE
P06BasilHerb5.0012FALSE
P07AloeSucculent9.5015TRUE
P08HibiscusFlowering18.006FALSE

Q1. How many fields and how many records does the table have?

Show answer

Fields are the columns: PlantID, Name, Type, Price, Stock, Indoor, so 6 fields. Records are the data rows P01 to P08, so 8 records. The header row is not a record.

Q2. Which field is the most suitable primary key, and why are Type and Indoor unsuitable?

Show answer

PlantID is different in every record and is created to be unique. Type repeats (Herb appears twice) and Indoor has only two values, so neither can identify one record.

Q3. Give the most suitable data type for Price, Stock and Indoor.

Show answer

Price: real (it has decimals such as 12.50). Stock: integer (whole numbers). Indoor: Boolean (TRUE or FALSE).

Q4. Write a query that shows the Name of every herb. Give the result.

Show answer
SELECT Name
FROM Plants
WHERE Type = "Herb"

Records P04 and P06 pass. Result: Mint, Basil.

Q5. Write a query for the Name and Price of plants costing less than 10, and state how many rows return.

Show answer
SELECT Name, Price
FROM Plants
WHERE Price < 10

Cactus 6.00, Mint 4.50, Basil 5.00, Aloe 9.50 pass. 4 rows.

Q6. Write a query that shows the Name of every plant that is out of stock.

Show answer
SELECT Name
FROM Plants
WHERE Stock = 0

Only Rose has Stock 0. Result: Rose.

Q7. What does this return?

SELECT Name FROM Plants
WHERE Indoor = TRUE AND Price >= 9.5
Show answer

Indoor plants: Fern 12.50, Cactus 6.00, Orchid 28.00, Aloe 9.50. Price at least 9.5: Fern, Orchid, Aloe pass; Cactus fails. Result: Fern, Orchid, Aloe.

Q8. Write a query for the Name of indoor plants, most expensive first, and give the result.

Show answer
SELECT Name
FROM Plants
WHERE Indoor = TRUE
ORDER BY Price DESC

Indoor prices: Orchid 28.00, Fern 12.50, Aloe 9.50, Cactus 6.00. Result: Orchid, Fern, Aloe, Cactus.

Q9. A student wants herbs or succulents that cost more than 6, but writes:

SELECT Name FROM Plants
WHERE Type = "Herb" OR Type = "Succulent" AND Price > 6

Give the rows this actually returns, then correct the query.

Show answer

AND is worked out first: Herb, OR (Succulent AND Price > 6). Mint and Basil pass as herbs. Cactus (6.00) fails. Aloe (9.50) passes. Actual result: Mint, Basil, Aloe.

Corrected query:

SELECT Name FROM Plants
WHERE (Type = "Herb" OR Type = "Succulent") AND Price > 6

This returns Aloe only, because Mint, Basil and Cactus are all 6 or less.

Q10. Explain why this query returns no rows.

SELECT Name FROM Plants
WHERE Type = "Succulent" AND Stock > 20 AND Indoor = FALSE
Show answer

Succulents are Cactus and Aloe. Stock above 20 leaves Cactus (25) only, since Aloe has 15. Cactus has Indoor = TRUE, so it fails Indoor = FALSE. No record passes all three, so no rows come back. The query is valid, but the single record that passes two tests fails the last one.

If you got these wrong

Add each slip to your mistake log with its cause, and retry the query in the read-only SQL practice lab a few days later. Back to the module overview to plan the next topic.

If the same errors keep returning, our teachers can help through online one-to-one Computer Science tuition.

Updated:

Your next step

If you keep missing the same kind of question in this set, a one-to-one teacher can sit with your answers and show you which step of your reasoning goes astray.

Paid one-hour trial at your assigned teacher’s confirmed rate, starting from RM80. Other fees, schedules and ongoing arrangements are confirmed directly with your teacher after the trial class.

Tuition is arranged with a parent or guardian. Send them this page on WhatsApp and they can enquire for you.

Parent or guardian? Enquire here

9,000+ students helped through our service