In MySQL, an alias is a temporary name assigned to a table or column for the duration of a query. Aliases improve readability and simplify queries — especially joins or queries with long identifiers.
AS keyword).
-- Syntax for Column Alias (rename a column in SELECT)
SELECT column_name AS alias_name
FROM table_name;
-- Syntax for Table Alias (give a temporary name to a table)
SELECT column_name
FROM table_name AS alias_name;
-- Using column alias to rename 'student_name' as 'name' and 'student_id' as 'id'
SELECT student_name AS name, student_id AS id
FROM students;
-- Using table alias 's' for the 'students' table and filtering by age
SELECT s.student_name, s.student_id
FROM students AS s
WHERE s.student_age > 18;
student_name AS name, the result set column will be labeled name.students AS s lets you reference the table as s (handy for joins or long table names).SELECT student_name name also works, but using AS increases clarity.customer_total instead of ct) for maintainability.product_name and price from products, aliasing them to name and cost.students (alias s) with courses (alias c) and select student name and course title.first and last using column aliases.