Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
A stationery cupboard keeps its pens in a table Pens.
PenID Colour Ink Stock
W1 Blue Gel 25
W2 Black Ball 40
W3 Red Gel 8
W4 Green Felt 12
W5 Blue Ball 33SELECT Colour, Stock
FROM Pens;A query starts SELECT (the fields to output, with commas between them, in the order you want) and FROM (the table). A semicolon ends it. With no condition, every record is output, in the order of the table.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Step 1. The records. There is no WHERE, so all records are output, in the order of the table.
Step 2. The fields. The script selects Colour and Stock, so the output has columns, Colour first.
Step 3. The output.
SELECT Colour, Stock
FROM Pens;The output:
Colour Stock
Blue 25
Black 40
Red 8
Green 12
Blue 33Answer: (a) rows and columns. (b) Blue, ; Black, .
Log in to join the discussion.
Loading…