In MySQL, aliases are used to provide alternative names for columns or tables in a query result.
This can make the output more readable or provide shorter names for complex expressions.
We can use aliases to provide alternative names for the columns in the result set. This is particularly useful when dealing with expressions or calculated values.
SELECT product_name AS "Product Name", category AS "Product Category" FROM products;
Table aliases are used to provide a shorthand notation for table names in a query, especially when dealing with multiple tables in a join.
SELECT p.product_name, p.category, o.purchase_by FROM products AS p JOIN orders AS o ON p.product_id = o.product_id;
Aliases can be used in the ORDER BY clause to refer to the result columns directly.
SELECT product_name, category, price AS product_price FROM products ORDER BY product_price ASC;