Stop 02 · Basic SELECT QueriesTopics · 1/8

Your First Query (SELECT, WHERE, ORDER BY)

Part of the SQL Roadmap

In short

Company data lives in databases with millions of rows. SQL is how you politely ask for just the rows you need, and it reads almost like plain English.

Most everyday SQL is three clauses: SELECT picks the columns, WHERE keeps only the rows you need and ORDER BY sorts the result. Together they answer a surprising number of real questions.

The jaadu pulls chosen books from a tall library shelf onto a cart.

Think of it like this

Asking the librarian

You don't carry the whole library home. You tell the librarian: "Only the titles and authors (SELECT), from the fiction shelf (FROM), published after 2015 (WHERE), newest first (ORDER BY)." SQL is that request slip, written for a database.

Watch it happen

How the database reads your query

FROM
WHERE
SELECT
ORDER BY
LIMIT

1/5First it opens the orders table: all 50,000 rows.

The big ideas

What you need to know

SELECT picks columns

Name the columns you need. SELECT * grabs everything, fine for a peek, wasteful in real queries.

WHERE filters rows

Use =, >, <, IN, BETWEEN, LIKE and combine with AND / OR. Text goes in single quotes.

ORDER BY sorts

ASC is the default. Add DESC for biggest or newest first.

NULL is special

Missing values are NULL. Use IS NULL or IS NOT NULL. = NULL never matches anything.

See it in code

Walk through the code

sql
1SELECT order_id, customer_id, amount, order_date2FROM orders3WHERE city = 'Pune'4  AND amount > 5005  AND order_date >= '2026-01-01'6ORDER BY amount DESC7LIMIT 10;

1/3Which columns, from which table.

The ten biggest Pune orders above ₹500 this year. LIMIT works in PostgreSQL, MySQL and SQLite. SQL Server uses TOP instead.

Save yourself the pain

Common mistakes

Oops

Writing WHERE discount = NULL to find missing discounts.

Do this instead

Use WHERE discount IS NULL. Comparing anything to NULL with = gives unknown, so no rows match.

Oops

Mixing AND and OR without brackets.

Do this instead

WHERE city = 'Pune' AND (status = 'paid' OR status = 'shipped'). Brackets make the logic clear.

Your mission

Your first five queries

~25 min

Quick check

In which order does the database actually process these clauses?

Go deeper

  1. 1Write a query that lists customers from one city, sorted by name.
  2. 2Change the WHERE condition three times and predict the row count before you run it.
  3. 3Read each query back as an English sentence to check it asks what you meant.

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