This topic summary covers Knowledge Organiser: SQL within SQL for GCSE Computer Science. Revise SQL in 3.7 Relational Databases and SQL for GCSE Computer Science with 19 exam-style questions and 10 flashcards. This topic shows up very often in GCSE exams, so students should be able to explain it clearly, not just recognise the term. It is section 9 of 9 in this topic. Use this topic summary to connect the idea to the wider topic before moving on to questions and flashcards.
Knowledge Organiser: SQL
Key Terms
- SQL: Structured Query Language — used to query and manage databases
- SELECT: Specifies which columns to retrieve
- FROM: Specifies the table to query
- WHERE: Filters rows by a condition
- ORDER BY: Sorts the results (ASC = ascending, DESC = descending)
- Wildcard (*): Selects all columns in a table
Must-Know Facts
- SQL keyword order: SELECT ... FROM ... WHERE ... ORDER BY
- String values in WHERE must be in quotes:
WHERE city = "London" - Number values do not use quotes:
WHERE age > 16 - Use AND to require multiple conditions; use OR for either condition
SELECT *returns all columns; name specific columns to limit output- ASC sorts lowest to highest; DESC sorts highest to lowest
Key Concepts
- Get all data:
SELECT * FROM Students - Filter rows:
SELECT name FROM Students WHERE age > 16 - Sort results:
ORDER BY score DESC - Multiple conditions:
WHERE age >= 16 AND city = "London" - Memory aid: S-F-W-O — Select, From, Where, Order by
Common Mistakes
- Getting the SQL keyword order wrong: The correct order is SELECT ... FROM ... WHERE ... ORDER BY — putting WHERE before FROM will cause a syntax error
- Forgetting quotes around string values: String comparisons in WHERE require quotes:
WHERE name = "Ali"; numeric comparisons do not:WHERE age > 16 - Using = instead of > or < for numeric ranges:
WHERE age = 16only matches exactly 16; use>=or<=for ranges - Forgetting ORDER BY comes last: ORDER BY must appear after WHERE — placing it in the middle causes a syntax error
- Confusing AND and OR in WHERE clauses: AND requires both conditions to be true; OR requires at least one — mixing them up produces incorrect results
Practice questions for SQL
Which SQL keyword is used to choose which columns to retrieve from a database table?
Explain the difference between using AND and OR to combine conditions in an SQL WHERE clause. Give an example of when each would be used.