Imagine a students table with the columns name, age and city. SELECT asks the database for some of that data.
SELECT name, age
FROM students
WHERE city = 'Siem Reap'
ORDER BY age DESC;Reading the query
SELECT name, agechooses the columns.FROM studentsnames the table.WHEREkeeps only matching rows.ORDER BY age DESCsorts from oldest to youngest.
Code examples
-- students: (Dara, 19, Phnom Penh), (Sophea, 21, Siem Reap), (Vuthy, 20, Siem Reap)
SELECT name FROM students WHERE city = 'Siem Reap';Expected output
Sophea Vuthy
Common mistakes
Common mistake: Using double quotes for text
In standard SQL, text values use single quotes: 'Siem Reap'. Double quotes are for column names.
Check your understanding
3 quick questions about this lesson.