- Define and explain SELECT Queries in your own words
- Use key terms such as query accurately
- Apply what you have learned to new examples and questions
- Avoid the common mistakes learners make with this topic
This lesson focuses on SELECT Queries: retrieve exactly the data you need with SELECT, WHERE and ORDER BY.
Retrieve exactly the data you need with SELECT, WHERE and ORDER BY.
Key ideas
Keys stop data going missing
A primary key guarantees every row can be found exactly once — without one, two customers called 'Smith' become indistinguishable. Foreign keys then link tables: an order row stores the customer's ID rather than copying their whole address, so an address change is updated in one place only. This is the foundation of reliable data.
SQL describes what, not how
You write SELECT Name FROM Students WHERE Year = 12 and the database works out how to find the rows — SQL is declarative. WHERE filters rows, ORDER BY sorts them, and JOIN combines tables via their keys. Because you describe the result you want, the same query works on ten rows or ten million.
Key term — query: A question asked of a database in SQL — most famously a SELECT statement that retrieves matching rows.
True or false: SQL tells the database exactly how to find the data, step by step.
False — SQL is declarative: you describe what you want and the database engine decides how to retrieve it.
Answer: False — SQL is declarative: you describe what you want and the database engine decides how to retrieve it.
- Forgetting the WHERE clause in an UPDATE or DELETE Correction: UPDATE Students SET Year = 13 with no WHERE changes every row — always write the WHERE first, or test with a SELECT using the same condition.
- Storing the same fact in two tables Correction: store it once and link with a foreign key — duplicated data drifts out of sync when only one copy is updated.
Practice
It is the unique identifier for a row — duplicates or blanks would make it impossible to pinpoint exactly one record.
A foreign key — it stores the primary key of a row in the Customers table, linking each order to its customer.
SELECT Title, Author FROM Books WHERE Year = 2010;.
One row: Leo — only Leo has Year 10.
Quick check
Which of these best defines "query"?
What is wrong with DELETE FROM Students; and how do you fix it?
- SELECT Queries: retrieve exactly the data you need with SELECT, WHERE and ORDER BY.
- Keys stop data going missing: A primary key guarantees every row can be found exactly once — without one, two customers called 'Smith' become indistinguishable.
- table: A database structure of rows (records) and columns (fields), storing one type of thing — for example, one table per customer, one per order.
- Watch out for: forgetting the WHERE clause in an UPDATE or DELETE