Looking inside a table
Hermione hands Harry read access to the customers table and asks him to pull up every customer NOVA has.
So I just… open the table and look?
In a spreadsheet, sure. But a real table can have millions of rows — you don’t scroll through it, you ask it a question. SQL is how you ask.
The most basic question you can ask a database is: “show me some data.” In SQL that’s a single statement built from two keywords: SELECT, which columns you want, and FROM, which table to get them from.
SELECT: “What do I want to see?” FROM: “Where should I look?”
The star, *, means “every column.” It’s the fastest way to see everything a table holds:
SELECT * FROM customers;Harry: “That’s a lot of columns I don’t actually need right now — I just want the names.” Naming exactly the columns you want works the same way:
SELECT name FROM customers;List more than one column by separating them with commas:
SELECT name, country FROM customers;Running…
Try it: What happens if you swap the order — SELECT country, name FROM customers?
Run your query to see results here.
The columns come back in whatever order you listed them in the SELECT clause — country first, then name. SQL doesn’t care how the columns are stored inside the table; it only cares about the order you asked for them.
NOVA’s support team just asked for a quick list of every customer’s name and email — nothing else. Write the query.
Hint 1
You already know how to pick out specific columns instead of using *.
Hint 2
Which two columns does support actually need here?
Hint 3
SELECT name, email FROM customers;
Solution
Running…
Every SQL query you write from here on starts the same way: decide which table you’re asking (FROM), then decide which columns you actually need (SELECT). Using * is fine for poking around, but naming columns is almost always better once a query matters — it’s clearer to read, and it doesn’t quietly change if someone adds a column to the table later.
SELECT decides which columns you see. FROM decides which table you’re asking. * means all columns — but naming them is usually better.