Script Valley
SQL for Developers (Not DBAs)
Foundations: How Databases ThinkLesson 1.2

Writing your first SELECT query โ€” columns, aliases, and literals

SELECT syntax, column selection, star selector, column aliases, literal values, query execution order

SELECT Is Not Magic โ€” It Is a Filter

A SELECT statement tells the database: give me these columns from this table. The database scans the table, picks the columns you asked for, and returns the result set.

-- Get every column (avoid in production โ€” expensive)
SELECT * FROM products;

-- Get specific columns only
SELECT name, price FROM products;

-- Rename a column in the result using AS
SELECT name AS product_name, price AS unit_price FROM products;

Aliases Don't Change the Table

The AS keyword renames a column in the result only. The actual table is untouched. Aliases are useful when your app reads column names from the result set โ€” you control those names here instead of in application code.

Literal Values in SELECT

You can SELECT a constant alongside real columns. This is useful for adding a static label to every row in a result:

SELECT name, price, 'USD' AS currency FROM products;

Every row gets the string USD in the currency column even though that column doesn't exist in the table.

Execution Order Matters Later

SQL doesn't run top-to-bottom like code you write. The logical order is: FROM โ†’ WHERE โ†’ SELECT โ†’ ORDER BY. SELECT runs after filtering. You'll feel this when aliasing columns โ€” you can't use a SELECT alias inside a WHERE clause in the same query.

Up next

Filtering rows with WHERE โ€” operators and conditions

Sign in to track progress

Writing your first SELECT query โ€” columns, aliases, and literals โ€” Foundations: How Databases Think โ€” SQL for Developers (Not DBAs) โ€” Script Valley โ€” Script Valley