Asking Questions · Episode 1

Looking inside a table

SELECTFROM*selecting columns
The story

Hermione hands Harry read access to the customers table and asks him to pull up every customer NOVA has.

Harry

So I just… open the table and look?

Hermione

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 concept

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?”

Build the query

The star, *, means “every column.” It’s the fastest way to see everything a table holds:

query.sql
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:

query.sql
SELECT name FROM customers;

List more than one column by separating them with commas:

query.sql
SELECT name, country FROM customers;
Run it
query.sql

Running…

Try it: What happens if you swap the order — SELECT country, name FROM customers?
experiment.sql

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.

Your turn

NOVA’s support team just asked for a quick list of every customer’s name and email — nothing else. Write the query.

Opens in a new window, full width — come back here once you’re done.
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
solution.sql

Running…

Debrief

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.

One thing to remember

SELECT decides which columns you see. FROM decides which table you’re asking. * means all columns — but naming them is usually better.