Databases & SQL
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version.
A database stores tables
- A database keeps data in tables, like a spreadsheet.
- Each row is a record; each column is a field.
- We ask questions in a language called SQL.
SELECT: choose columns
SELECTpicks which columns to show.FROMnames the table to read.*means "all columns".
SELECT name, grade FROM student;
WHERE: filter rows
WHEREkeeps only the rows whose condition is true.- Put text in single quotes:
'A'.
Explore
SELECT … WHERE, visualized
WHERE keeps only matching rows; SELECT then keeps only the chosen columns.
SELECT name FROM student WHERE grade = 'A';
ORDER BY: sort the results
ORDER BYsorts the rows by a column.- Add
DESCfor largest first, orASC(the default) for smallest first.
SELECT name, age FROM student ORDER BY age DESC;
In the exam: SQL
- IGCSE uses exactly these clauses:
SELECT … FROM … WHERE … ORDER BY.
SELECT Name, Grade
FROM Student
WHERE Grade = 'A';
Common mistakes
- Text values go in single quotes:
WHERE name = 'Ann'. SELECTchooses the columns;WHEREfilters the rows.
Now you try
- Write one SQL query for each task.
- Press Check answer to run it against the table.
Show the name of every student. (Use SELECT name FROM student;.)
Click Run to see the output here.
Show the name and grade of every student whose grade is A. (Text goes in single quotes: 'A'.)
Click Run to see the output here.
Show the name of every student, oldest first (sort by age in descending order).
Click Run to see the output here.