SELECT
u.first_nameAS name,
o.total_amountAS order_total
FROM users AS u
JOIN orders AS o ON o.user_id= u.id;
Output
-- name | order_total
-- Alice | 149.99
Note AS is optional in most databases but improves clarity. You cannot reference a column alias in the WHERE clause of the same query - use a subquery or CTE instead.
Note ALTER TABLE syntax varies across databases. PostgreSQL uses ALTER COLUMN ... TYPE. MySQL uses MODIFY COLUMN. Adding NOT NULL to a column with existing NULLs will fail - update the data first.
Frequently asked questions
How do you rename column?
SQL covers this with 2 copy-ready snippets on this page. The "Column and Table Aliases" snippet in SQL uses `SELECT column AS alias_name FROM table AS t;`.
Which statement does the SQL example use?
The "Column and Table Aliases" snippet uses `SELECT column AS alias_name FROM table AS t;`, from the Basic Queries section of the SQL cheat sheet.
What other SQL snippets are shown for "rename column"?
Besides "Column and Table Aliases", this page also shows "ALTER TABLE".
Is there anything to watch out for?
Yes. For "Column and Table Aliases": AS is optional in most databases but improves clarity. You cannot reference a column alias in the WHERE clause of the same query - use a subquery or CTE instead.