Skip to main content

Aliases

Aliases rename columns or tables within a query.

They improve readability and make result headers friendlier.

Core Concepts

flowchart LR
A[Original column/table names] --> B[Apply aliases with AS]
B --> C[Readable query + output]
Alias typeExampleUse case
Column aliasSELECT full_name AS nameBetter output headers
Table aliasFROM employees AS eShorter references

Code Examples

-- Setup sample table.
CREATE TABLE sales (
sale_id INTEGER PRIMARY KEY,
item_name TEXT NOT NULL,
amount REAL NOT NULL
);

INSERT INTO sales (item_name, amount)
VALUES ('Keyboard', 89.99);
Expected output
Table created and one row inserted.
-- Use aliases for output readability.
SELECT
item_name AS product,
amount AS total_amount
FROM sales AS s;
producttotal_amount
Keyboard89.99

SQLite-Specific Nuances

SQLite Nuance

Column aliases affect the result-set header, not the underlying table schema.

Common Pitfalls / Best Practices

Pitfall

Using confusing one-letter aliases everywhere, even in simple single-table queries.

Best Practice

Use short, meaningful aliases (cust, ord, total_amount) and keep naming consistent.

Quick Challenge

Return item_name as item and amount as price from sales.

View Solution
SELECT
item_name AS item,
amount AS price
FROM sales;
itemprice
Keyboard89.99