Content
Aliases give temporary names to columns or tables. Improve readability and simplify complex queries.
Column Alias
SELECT first_name AS name FROM customers;
SELECT COUNT(*) AS total_orders FROM orders;
Table Alias
SELECT c.name, o.total
FROM customers c
JOIN orders o ON c.id = o.customer_id;
Alias with Spaces
SELECT first_name AS "First Name" FROM customers;
Calculated Column Alias
SELECT
price,
quantity,
price * quantity AS total_value
FROM order_items;
Alias in Subqueries
SELECT * FROM (
SELECT customer_id, SUM(total) as total_spent
FROM orders
GROUP BY customer_id
) AS customer_totals
WHERE total_spent > 1000;
Self-Documenting Queries
SELECT
c.name AS customer_name,
COUNT(o.id) AS order_count,
SUM(o.total) AS lifetime_value
FROM customers c
LEFT JOIN orders o ON c.id = o.customer_id
GROUP BY c.id;
Generate Aliased Queries
AI2sql adds meaningful aliases automatically.


