Stop 02 · Basic SELECT QueriesTopics · 2/8

SELECT and FROM

Part of the SQL Roadmap

In short

Every read query you will ever write starts with the same two words. SELECT says which columns you want, FROM says which table to take them from.

SELECT lists the columns you want and FROM names the table they come from. Every read query starts here.

The jaadu reaches up to a neighbourhood kirana shelf and pulls down two chosen biscuit packets while leaving the rest in place.

Think of it like this

Asking at the kirana store

You don't walk behind the counter. You tell the shopkeeper: "From the biscuit shelf, give me Parle-G and Marie." FROM is the shelf, SELECT is the items you name. The shopkeeper fetches just those and hands them over.

Watch it happen

SELECT picks columns from the table

order_id
0
customer
1
city
2
amount
3
status
4

1/4FROM orders: the database opens the orders table. These are its five columns.

The big ideas

What you need to know

SELECT is the column list

Separate column names with commas. No comma after the last one.

FROM names the source

Usually a table. Later it can be a join of tables or even another query.

All rows by default

Without WHERE or LIMIT you get every row in the table. On big tables that can be millions.

SELECT can work without a table

SELECT 2 + 2; runs in PostgreSQL and MySQL. Oracle needs FROM dual.

See it in code

Walk through the code

sql
1SELECT name, city2FROM customers;3 4SELECT order_id, amount, order_date5FROM orders;6 7SELECT 'Namaste' AS greeting, 18 * 2 AS answer;

1/3Two columns from customers, every row.

Three basic reads. Keywords are not case-sensitive, but writing them in capitals makes queries easier to scan.

Save yourself the pain

Common mistakes

Oops

Leaving a trailing comma: SELECT name, city, FROM customers.

Do this instead

The last column has no comma after it. The error usually says something near FROM.

Oops

Spelling a column wrong and assuming the table is broken.

Do this instead

Check the exact column names in your client's sidebar. column "nmae" does not exist means a typo.

Your mission

Five plain reads

~15 min

Quick check

What does SELECT city, name FROM customers; return?

Go deeper

  1. 1Select three named columns from a table instead of using SELECT *.
  2. 2Write 5 queries that each answer a simple question about one table.
  3. 3Get used to formatting each clause on its own line for readability.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge