How does SQL know what information to display?
A database table contains several fields, but a query does not always need to display all of them.
SELECT chooses the field or fields to return. FROM chooses the table where those fields are stored.
In Cambridge IGCSE Computer Science (0478 and 0984), SELECT specifies the exact field or comma-separated fields to display in a query output, while FROM identifies the single table where those records are stored. Without a WHERE clause, every record in the table is returned.
Practise selecting one or multiple fields from the Students table to avoid returning unnecessary columns in Topic 9.3 exam questions.
A database table contains several fields, but a query does not always need to display all of them.
SELECT chooses the field or fields to return. FROM chooses the table where those fields are stored.
SELECT Name FROM Students;
The database contains the source data. The query chooses one field from the table. The output displays only that selected field.
| StudentID | Name | Age | House |
|---|---|---|---|
| 101 | Alice | 15 | Blue |
| 102 | Ben | 16 | Green |
| 103 | Chen | 15 | Blue |
SELECT Name FROM Students;
SELECT Name, Age FROM Students;
Choose the Name and Age fields from the Students table.
| Name | Age |
|---|---|
| Alice | 15 |
| Ben | 16 |
| Chen | 15 |
When an exam asks for the output of a query, look at the fields listed after SELECT.
This copies every field from the table.
Only Name was selected.