Asking questions with SQL
About this lesson: Asking questions with SQL
In short
SQL asks a database questions. SELECT picks fields, FROM names the table, WHERE picks records.

What you'll explore
- SELECT and WHERE: Choose fields and records
- SQL asks a database questions. SELECT picks fields, FROM names the table, WHERE picks records.
- AND, OR and ORDER BY: Combine and sort
- AND needs both conditions; OR needs either. ORDER BY sorts the results. Try each query.
- COUNT and SUM: One answer from many
- Aggregate functions summarise: COUNT counts records, SUM adds a field, AVG finds the mean, MAX and MIN find extremes.
- From words to SQL: Turn a question into conditions
- Read a question carefully and turn each part into a condition.
- Check yourself: Read a query
- SELECT Name FROM Planets WHERE Diameter > 50000;
Also in this lesson
- Step by step
- Watch out for these
- More than the lesson
- Stretch your brain
- Try it yourself
Words to know
- SQL
- Structured Query Language, used to work with databases.
- Query
- A question asked of a database.
- SELECT
- Chooses the fields to show.
- WHERE
- Filters records by a condition.
- ORDER BY
- Sorts the results.
- Aggregate function
- A function that summarises many records, like COUNT.
Sources
- SQLite documentation: SELECT
- NASA Planetary Fact Sheet (diameters and rotation periods)
- OWASP: SQL Injection Prevention Cheat Sheet
- Raspberry Pi Foundation, Isaac Computer Science: SQL
← Designing a database table · Logic gates and truth tables →