SQL Aliases
Give temporary names to columns and tables
✅ What You Will Learn
An alias is a temporary name you assign to a column or table in a query. Aliases make your output more readable and your query easier to write — especially when dealing with long table names or calculated columns.
Aliases only exist for the duration of the query. They do not change the actual column or table name in the database.
📋 The orders table — aliases rename columns in the result
| order_id | customer_name | product | amount |
|---|---|---|---|
| 1001 | Rahul Sharma | Laptop | 45000 |
| 1002 | Priya Verma | Mobile Phone | 18000 |
| 1003 | Amit Kumar | Headphones | 3500 |
| 1004 | Sneha Kapoor | Laptop | 52000 |
| 1005 | Vikram Singh | Tablet | 28000 |
Syntax
Examples
📌 Key Points to Remember
- ✓AS keyword creates an alias — it is optional but recommended for readability
- ✓Table aliases are especially important in JOINs
- ✓Column aliases can be used in ORDER BY but not in WHERE or HAVING
- ✓Aliases with spaces need double quotes: AS "Total Revenue"
- ✓Once you define a table alias, you must use it throughout the query
🏢 Real-World Application
Aliases make SQL queries readable and professional. Without table aliases, a JOIN query becomes verbose: SELECT orders.customer_name, orders.amount, customers.city FROM orders INNER JOIN customers ON orders.customer_id = customers.customer_id. With aliases: SELECT o.customer_name, o.amount, c.city FROM orders o INNER JOIN customers c ON o.customer_id = c.customer_id. In data analyst interviews, clean SQL with aliases is expected — messy queries without them suggest inexperience.
⚠️ Common Mistakes to Avoid
❓ Frequently Asked Questions
What is an alias in SQL?
An alias is a temporary name assigned to a column or table using AS. Column aliases rename the output column for readability. Table aliases (FROM orders o) shorten table names in long queries.
Is AS required for aliases in SQL?
No — AS is optional in most databases. SELECT amount gst_amount works the same as SELECT amount AS gst_amount. But using AS explicitly makes queries clearer and more portable.
Can I use a column alias in WHERE?
No. WHERE is evaluated before the SELECT clause processes aliases. Use the original column expression in WHERE. You can use column aliases in ORDER BY and (in some databases) HAVING.
Can two columns have the same alias in SQL?
Technically yes but it creates confusion. Different columns with the same alias are allowed syntactically in most databases, but downstream tools may only show one of them. Always use unique aliases.
✏️ Practice Exercise
Rewrite a previous query you wrote — add meaningful aliases to all columns and use table aliases if there are JOINs.
Learn SQL with Live Trainer Guidance
These tutorials give you the theory. Our live SQL course at EVIKA Academy, Noida teaches you to apply SQL on real company datasets — with a trainer who uses it daily at MakeMyTrip.