The SELECT statement is the single most-used piece of SQL — it's how you read data out of a table. Nearly every other topic in this course, from filtering with WHERE to joining multiple tables, builds directly on top of a basic SELECT.
At its simplest, a SELECT statement names the columns you want and the table to pull them from. The database returns a result set — a temporary table of matching rows — rather than changing anything in the underlying data.
Basic Syntax
Assuming our running employees table (id, name, department, salary, hire_date):
SELECT name, department
FROM employees;
Result:
name | department
--------------|------------
Alice Chen | Engineering
Marco Diaz | Sales
Priya Nair | Engineering
SELECT * vs Naming Columns
SELECT * returns every column in the table, which is convenient while exploring data but considered bad practice in real application code — it pulls more data than you may need, and breaks silently if someone adds a new column your code wasn't expecting.
-- Quick exploration — fine for ad-hoc use
SELECT * FROM employees;
-- Production query — explicit and predictable
SELECT id, name, salary FROM employees;
Column Aliasing with AS
You can rename a column in the result set using AS — useful for giving computed columns a readable name, or for making a report-friendly header.
SELECT
name AS employee_name,
salary * 12 AS estimated_annual_bonus_pool
FROM employees;
Result:
employee_name | estimated_annual_bonus_pool
--------------|----------------------------
Alice Chen | 1140000.00
Marco Diaz | 660000.00
The AS keyword is optional in most databases (salary * 12 estimated_annual_bonus_pool works too), but writing it explicitly makes a query easier to read at a glance.
Order of Execution, Briefly
It's worth knowing that SQL doesn't run top-to-bottom the way the keywords are written — FROM is conceptually evaluated before SELECT picks which columns to return, and before any WHERE filtering or ORDER BY sorting happens. You don't need to memorize this to write working queries, but it explains why, for example, you can't reference a column alias inside the same statement's WHERE clause in most databases — the column list hasn't been resolved yet at that point.
Once SELECT feels comfortable, filtering rows with WHERE is the natural next step — right now every query above returns the whole table, and that's rarely what you actually want.
