SQL Query Editor Ctrl + Enter to run
Query Results Results appear here
Database Browser — view the data
Look at the available data before writing your query. Choose a table to view its records.
SQL Tutor — help with writing SQL
If you are unsure what to type, use this section before trying the task. SQL is a language used to ask questions of databases.
1. The basic SQL pattern
Most of the SQL you will use follows this pattern:
Think of it as:
- SELECT – What information do I want?
- FROM – Which table contains it?
- WHERE – Which records do I want?
- ORDER BY – How should the results be arranged?
2. SQL commands
Clicking a command puts an example into the SQL editor.
3. Choosing fields
Use * when you want every field.
Or name the fields you want:
4. Searching with WHERE
WHERE lets you choose only records that meet a condition.
Text values normally need quotation marks:
Numbers do not need quotation marks:
5. AND and OR
AND means both conditions must be true.
OR means either condition can be true.
6. Searching text with LIKE
LIKE is useful when you only know part of some text value.
The % means "anything can come after this".
7. Sorting results
ORDER BY sorts your results.
ASC = smallest to largest / A to Z
DESC = largest to smallest / Z to A
8. A useful way to build SQL
- Find the table.
- Decide which fields you need.
- Add SELECT.
- Add FROM.
- Ask yourself whether you need WHERE.
- Add AND or OR if you have more than one condition.
- Add ORDER BY if the question asks you to sort.