Aliases in Joins
As SQL queries grow more complex, using aliases improves readability and structure.
Aliases assign temporary, clear names to tables and columns, making multi-join queries easier to follow.
Table Aliases
Use the AS keyword (or omit it) to give a meaningful alias to a table:
Table alias with AS
SELECT students.name, enrollments.class_id
FROM students AS students
JOIN enrollments AS enrollments
ON students.student_id = enrollments.student_id;
You can also omit AS:
Table alias without AS
FROM students students
JOIN enrollments enrollments ...
This avoids repeating long table names and is useful when joining multiple tables.
Column Aliases
Use AS to rename output columns for clarity:
Column alias
SELECT
students.name AS student_name,
enrollments.class_id AS course
FROM students students
JOIN enrollments enrollments
ON students.student_id = enrollments.student_id;
Output
| student_name | course |
|---|---|
| Alex | A1 |
| Sara | A2 |
Column aliases make query results easier to read and are especially helpful in dashboards and reports.
Why are aliases useful in joins?
You should use aliases when:
- When joining multiple tables with similar column names
- When performing self joins (you must alias the same table twice)
- When writing queries that need to stay readabl for analysis, reporting, or BI dashboards
Want to learn more?
Join CodeFriends Plus membership or enroll in a course to start your journey.