PostgreSQL AS
The AS
keyword is used to provide an alias for columns or tables in your queries, improving readability and clarity.
Key Topics
1. Column Alias
SELECT first_name AS fname, last_name AS lname
FROM employees;
This changes the column headers in the result to fname
and lname
.
2. Table Alias
SELECT e.first_name, e.department
FROM employees AS e
WHERE e.salary > 50000;
Shortens the table name to e
for easier reference.
Best Practices
- Use aliases to shorten lengthy table names in complex joins.
- Make alias names descriptive to clarify the query context.
Key Takeaways
AS
improves readability by renaming columns or tables.- Aliases can reduce typing in complex queries with multiple joins.