Understand and write basic SQL queries including SELECT, WHERE, AND, OR, ORDER BY
📚 Databases – IGCSE Computer Science 0478
What is a Database?
Think of a database as a digital library. Just like books are organized by shelves, a database stores data in tables – rows are like books, columns are like the book’s title, author, and year. This structure lets us search, add, and change information quickly.
Basic SQL Syntax
- SELECT – choose which columns to display.
- WHERE – filter rows that meet a condition.
- AND / OR – combine multiple conditions. Example: $WHERE$
age > 18 AND gender = 'F' - ORDER BY – sort the results. Example: $ORDER BY$
score DESC
Analogy: Grocery Store Checkout
Imagine you’re at a grocery store. The SELECT statement is like choosing which items to put on the cart. The WHERE clause is like saying “only take items that are on sale.” AND means “and also” (both conditions must be true), while OR means “or” (either condition works). Finally, ORDER BY is like lining up your items by price from lowest to highest.
Example Queries
Suppose we have a table called Students with columns: id, name, age, grade, score.
| id | name | age | grade | score |
|---|---|---|---|---|
| 1 | Alice | 15 | 10 | 88 |
| 2 | Bob | 16 | 11 | 92 |
| 3 | Charlie | 15 | 10 | 75 |
| 4 | Diana | 16 | 11 | 85 |
SELECT name, score FROM Students;– Shows every student’s name and score.SELECT * FROM Students WHERE age = 15;– Only students who are 15 years old.SELECT name FROM Students WHERE grade = 11 AND score > 80;– 11th‑grade students with a score above 80.SELECT name, score FROM Students WHERE grade = 10 OR grade = 11 ORDER BY score DESC;– All 10th and 11th graders, sorted from highest to lowest score.
Exam Tips 🏆
- Read the question carefully – look for keywords like “all”, “only”, “greater than”, “less than”.
- Remember the order:
SELECT→FROM→WHERE→ORDER BY. - Use
ANDwhen you need both conditions true; useORwhen either condition is enough. - Test your queries mentally: what would the result set look like?
- Practice writing queries with sample data – the more you practice, the faster you’ll spot the right syntax.
Revision
Log in to practice.
1 views
0 suggestions