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

SELECT query diagram

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