SQL, Knowledge Organiser

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 = 16 only 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

PrepWise is a trading name of A3M Quality Solutions Limited, registered in England and Wales, company number 14959172. Registered office: 202 Stroud Road, Gloucester, GL1 5LA. ICO registration ZC267069.