Revise Computingrevisecomputing.co.uk
At a glanceFeaturesStudentsPricingHow it worksFree GCSE notesExam dates
At a glanceFeaturesStudentsPricingHow it worksFree GCSE notesExam dates

Knowledge organisers / Additional Programming Techniques

The use of SQL to search for data

All topicsPractise exam questions
Knowledge organiser

Additional Programming Techniques

2.2.3e

SQL commands:SELECT, FROM, WHERE

What you need to know

SQL (Structured Query Language) is used to search for, manage, and retrieve data from a database. The three key SQL commands you need to know are SELECT (which fields to return), FROM (which table to search), and WHERE (which conditions to apply). You can select specific fields, multiple fields, or all fields using the wildcard *.

Key points

  • Definition:Database: an organised collection of related data stored in tables that allows data to be easily accessed, managed and queried.
  • SELECT specifies which field(s) to retrieve. List only the fields asked for — don't use * if specific fields are needed.
  • FROM specifies which table to search in. SPELLING MUST BE EXACT (e.g. TblResult not TblResults).
  • WHERE applies a condition to filter the results, e.g. WHERE YearGroup = 11.
  • SELECT * returns ALL fields from the table.
  • Multiple conditions can be combined with AND and OR, e.g. WHERE DroneType = "Octocopter" AND Mileage > 50000.
  • Use = for comparison in SQL (not ==, although == is accepted in some exam mark schemes).
  • Exam Tip:No spaces in field names. Spelling of table and field names must match exactly what is given (TblResult not TblResults).
  • Exam Tip:The order must be correct: SELECT ... FROM ... WHERE ...
  • Common Mistake:SELECT ALL is NOT valid SQL. Use SELECT * or list all field names separated by commas.
  • Common Mistake:IF is NOT valid SQL — use WHERE for filtering conditions.
  • Exam Tip:String values in WHERE must use quotation marks: WHERE SensorType = "Door". Numeric values don't need quotes: WHERE Mileage > 50000.
  • Exam Tip:When asked for multiple conditions, combine with AND: WHERE SensorType = "Door" AND Length > 20.
  • SQL is not case-sensitive for keywords, but the convention is to write them in UPPERCASE.

Code examples

SQL query examples
sql
-- Get all unsold cars
SELECT Model
FROM Cars
WHERE Sold = FALSE

-- Get multiple fields with conditions
SELECT Model, Manufacturer, Price
FROM Cars
WHERE Sold = TRUE AND Price > 4000

-- Get all fields for Ford cars
SELECT *
FROM Cars
WHERE Manufacturer = 'Ford'