Topic 9 ยท Databases ยท 9.3

SELECT ... FROM Explained Simply

SELECT chooses the fields you want to see. FROM tells the database which table to use.

Invitation

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.

SELECT chooses the fields. FROM chooses the table.
Figure 1
Two keywords working together
SELECT Name
โ†“
Choose the Name field
โ†“
FROM Students
Use the Students table.
Big Idea

Read the query as a simple sentence

SQL QueryPlain English
SELECT Name
FROM Students;
SELECT NameChoose the Name field.
FROM StudentsUse the Students table.
Plain English: โ€œShow me every name from the Students table.โ€
How It Works

Keep the same three-step pattern

The database contains the source data. The query chooses one field from the table. The output displays only that selected field.

1. DATABASEStudents table
โ†’
2. QUERYSELECT Name FROM Students
โ†’
3. OUTPUTName field only
Database โ†’ Query โ†’ Output.
Worked Example

Select one field from the Students table

1. Database

StudentIDNameAgeHouse
101Alice15Blue
102Ben16Green
103Chen15Blue

2. SQL Query

SQLAsk
SELECT Name
FROM Students;

3. Output

Alice
Ben
Chen
Notice: StudentID, Age and House do not appear because they were not selected.
More Than One Field

Separate selected fields with commas

SQL QueryMeaning
SELECT Name, Age
FROM Students;

Query Meaning

Choose the Name and Age fields from the Students table.

Output

NameAge
Alice15
Ben16
Chen15
Use commas when selecting more than one field.
Exam Tip

Return only the fields named after SELECT

When an exam asks for the output of a query, look at the fields listed after SELECT.

1Find the selected fields.
2Find the table after FROM.
3Copy only those columns into the output.
Exam rule: SELECT chooses the fields. FROM chooses the table.
Common Mistake

Do not return the whole table

โœ— Incorrect output

101 Alice 15 Blue 102 Ben 16 Green 103 Chen 15 Blue

This copies every field from the table.

โœ“ Correct output

Alice Ben Chen

Only Name was selected.

Remember: the output must match the selected fields exactly.
Summary

Two keywords, one clear job each

SELECTChooses the fields to display.
FROMChooses the table to use.
OUTPUTShows only the selected fields.
Final rule: SELECT chooses. FROM locates.