SQL for Beginners
Learn how to ask a database for exactly the data you need. We’ll use a café menu and build one query at a time.
What is SQL?
SQL stands for Structured Query Language. You use it to work with data stored in tables. A table has rows and columns, much like a spreadsheet. In the drinks table below, each row represents one drink and each column stores a detail about it.
| name | category | price |
|---|---|---|
| Espresso | coffee | 3.00 |
| Latte | coffee | 4.50 |
| Matcha Latte | tea | 5.25 |
Write a SELECT query
SELECT chooses the columns you want. FROM names the table. This query returns each drink’s name and price.
SELECT name, price
FROM drinks;
Use commas between column names. To see every column while exploring a new table, use SELECT *.
Filter rows and sort the results
Add WHERE to keep matching rows and ORDER BY to set their order. Here, DESC puts the highest price first.
SELECT name, price
FROM drinks
WHERE category = 'coffee'
ORDER BY price DESC;
On the sample menu, this returns Latte first and Espresso second. Try changing 'coffee' to 'tea' and predict what you’ll see.
Try your first interactive lesson
Practice selecting columns in your browser and get immediate feedback.
Start the free SQL lesson