What is SQL?
SQL (Structured Query Language) is a language used to search, sort and edit the data held in a database. The most common IGCSE task is to retrieve selected records from a table.
The SELECT statement
A query names the fields to show with SELECT, the table to read with FROM, and an optional condition with WHERE. Results can be sorted with ORDER BY. Use * to show every field.
Example
List the name and price of every item costing more than 50 ringgit, cheapest first:
SELECT Name, Price FROM Products WHERE Price > 50 ORDER BY Price ASC;
Conditions and functions
Conditions use operators such as =, >, < and >=, and can be joined with AND or OR. Aggregate functions summarise data: SUM adds a numeric field and COUNT counts records; AVG, MAX and MIN are also available.
Key idea
Order of a basic query: SELECT fields FROM table WHERE condition ORDER BY field.
Remember
- Text values go in quotes:
WHERE Class = 'F5A'. ORDER BY … ASCsorts low to high;DESCsorts high to low.- End a statement with a semicolon.