Lesson Beginner

SELECT / FROM

Every SQL query answers two questions before anything else:
what columns do I want, and what table do they come from?
SELECT answers the first. FROM answers the second. The rest of SQL sits on top of that.

Pick Columns Deliberately #

List the columns you actually need after SELECT, separated by commas.

sql
SELECT
  id,
  status,
  total
FROM orders;

You can also write SELECT * to return every column. It is useful while exploring, but avoid it in saved or production queries. The output changes silently whenever the table changes, your queries pull more data than they need, and readers cannot tell from the query which columns matter.

Tip

**Use SELECT to explore, then rewrite with explicit columns before keeping the query around.* A named column list documents intent and survives schema changes without surprises.

FROM Is the Source of Rows #

FROM names the table that feeds SELECT.
If the table does not exist, or you misspell its name, the query fails before anything else runs. That is usually the first error you should check when a query will not parse.

Try It #

Run the query below as-is. Then change the column list and rerun. The goal is to see how the result shape changes when you SELECT different columns from the same FROM.

Loading SQL editor...

Mistakes to Watch For #

  • Leaving SELECT * in queries that other people or dashboards will rely on.
  • Typos in column or table names. Errors like column "prise" does not exist are almost always spelling.
  • Forgetting the comma between columns; SQL will interpret id status as "column id aliased as status", which silently returns the wrong thing.
  • Selecting from the wrong table because two tables have similar names.

Practice #

Write a query against the users table that returns three specific columns: id, email, and name. Use an explicit column list, not *.

Loading SQL editor...

Knowledge check #

3 questions

0 / 3 answered
  1. Why is SELECT * discouraged in production code?

  2. SELECT 1 + 1 AS x (no FROM clause). What does it return?

  3. Which is the logical order of evaluation (not the order you write the clauses)?

Next Step #

Continue to ORDER BY to control the order of rows in your result.