FutureLogic Blog → Databases → IGCSE 0478

What Do SQL SELECT and FROM Do?
Explained Simply

SQL (Structured Query Language) is the language used to retrieve data from a database. In a query, the SELECT clause chooses which fields (columns) to display, and the FROM clause names the specific table where that data is stored.

Write your first query on the Golden Biscuit Tin's BiscuitOrders table, compare named fields with SELECT *, and discover why row order is not guaranteed for Cambridge IGCSE Computer Science (0478 and 0984).

FutureLogic Education thumbnail: SQL SELECT – Choose Your Fields, with a chicken in glasses lifting two glowing columns out of a grid while Jacques the pigeon and a pirate parrot watch beside the Golden Biscuit Tin

What is SQL?

SQL stands for Structured Query Language. It is the language used to work with data stored in a database. A query is a request for data, like asking the database, “Show me the biscuit type and quantity of every order.”

All our examples use the Golden Biscuit Tin's BiscuitOrders table. If records, fields and primary keys are new to you, read Database Structure Explained first.

BiscuitOrders table
OrderIDBiscuitTypeQuantity
101Hobnob6
102Viennese Swirl4
103Hobnob8
104Hobnob2
SELECT chooses the fields. FROM chooses the table.

Cambridge syllabus focus

Topics 9.2–9.3: know that SQL is Structured Query Language, and understand SQL scripts that use SELECT and FROM to query a single table.

Your first query

Jacques wants to see which biscuits were ordered and how many, but he doesn't need the order numbers. He runs this query:

SELECT BiscuitType, Quantity
FROM BiscuitOrders;
  • SELECT BiscuitType, Quantity lists the fields to display. When there is more than one, separate them with commas.
  • FROM BiscuitOrders names the source table the data comes from.
  • The semicolon marks the end of the statement.
SELECT picks columns, FROM picks the tableThe BiscuitOrders table has three columns. The BiscuitType and Quantity columns are highlighted and copied into the output, which still has four rows. The OrderID column is greyed out. FROM BiscuitOrders OrderIDBiscuitTypeQuantity 101102103104 Hobnob6Viennese Swirl4Hobnob8Hobnob2 → SELECT BiscuitType, Quantity BiscuitTypeQuantity Hobnob6Viennese Swirl4Hobnob8Hobnob2 SELECT keeps 2 of the 3 fields. Every record is still returned: 4 rows in, 4 rows out.
Diagram 1: SELECT chooses columns (fields). Without WHERE, it does not remove any rows (records).
Output: 4 records, 2 fields
BiscuitTypeQuantity
Hobnob6
Viennese Swirl4
Hobnob8
Hobnob2

Notice two things. First, all four records are returned. SELECT chooses columns, not rows. Second, Hobnob appears three times. Each Hobnob order is a separate record, so each one appears in the output. SELECT does not merge or remove repeated values.

Check your understanding 1

How many records and how many fields would SELECT BiscuitType FROM BiscuitOrders; output?

Reveal answer

4 records and 1 field: Hobnob, Viennese Swirl, Hobnob, Hobnob.

Selecting every field with SELECT *

The asterisk * means “every field”. It is a shortcut for listing every field name:

SELECT *
FROM BiscuitOrders;
Output: 4 records, 3 fields
OrderIDBiscuitTypeQuantity
101Hobnob6
102Viennese Swirl4
103Hobnob8
104Hobnob2

SELECT BiscuitType, Quantity

4 × 2

4 records, only the 2 named fields.

SELECT *

4 × 3

4 records, every field in the table.

Both queries return the same four records, and Hobnob appears three times in both. The only difference is how many fields are shown.

Exam tip: If a question asks you to display particular fields, name them in SELECT. Using SELECT * shows extra fields the question did not ask for, and it may lose you the mark.

What order do the rows come out in?

The outputs above list orders 101 to 104, the order they were stored in. But SQL does not guarantee any row order unless the query says so. A database may return the same records in a different order, especially in a large table.

To control the order, add an ORDER BY clause. That is covered in SQL ORDER BY Explained.

Worked example: display the order numbers and quantities

Task: Write a query to display the OrderID and Quantity of every order.

  1. Which fields? OrderID and Quantity, so SELECT OrderID, Quantity.
  2. Which table? FROM BiscuitOrders.
  3. Are all records needed? Yes, so no WHERE clause is needed.
SELECT OrderID, Quantity
FROM BiscuitOrders;

Result: 4 records, each showing an OrderID and its Quantity: 101 and 6, 102 and 4, 103 and 8, 104 and 2.

Check your understanding 2

A student writes SELECT BiscuitOrders FROM Quantity;. What has gone wrong?

Reveal answer

The table name and the field name have been swapped. Field names go after SELECT and the table name goes after FROM: SELECT Quantity FROM BiscuitOrders;

Common Cambridge exam mistakes

✗ “SELECT BiscuitType shows each biscuit type once: Hobnob and Viennese Swirl.”

SELECT returns one row for every record, so the output is Hobnob, Viennese Swirl, Hobnob, Hobnob. Repeated values are not removed.

✗ “SELECT chooses which records appear.”

SELECT chooses the fields (columns). Choosing records (rows) is the job of WHERE.

Original FutureLogic exam-style practice

These are original teaching questions, not official Cambridge examination questions. The marks shown are a guide only.

Question 1 (2 marks)

Write an SQL query to display the OrderID and BiscuitType of every order in the BiscuitOrders table.

Reveal model answer
SELECT OrderID, BiscuitType
FROM BiscuitOrders;

1 mark for SELECT OrderID, BiscuitType and 1 mark for FROM BiscuitOrders.

Question 2 (2 marks)

State how many records and how many fields are output by this query, and explain why “Hobnob” appears more than once.

SELECT BiscuitType
FROM BiscuitOrders;
Reveal model answer

4 records and 1 field (1). Hobnob appears three times because there are three separate Hobnob orders/records, and SELECT outputs a value for every record (1).

Quick quiz

  1. What does SQL stand for?
  2. What is a query?
  3. What does * mean after SELECT?
  4. Without ORDER BY, is the row order guaranteed?

Quiz answers

Reveal all answers
  1. Structured Query Language.
  2. A request for data from a database.
  3. Every field in the table.
  4. No. Use ORDER BY to control it.

Final summary

SQL

Structured Query Language: the language used to query a database.

SELECT

Chooses the fields (columns) to display.

FROM

Names the source table.

SELECT *

Every field. The same 4 records are still returned.

SELECT picks the columns, FROM picks the table, and every record comes back until you add WHERE.

Ready to filter the orders?

SELECT and FROM return every record. WHERE lets you keep only the records you need, such as the Hobnob orders.