在MySQL中使用別名(alias)可以通過AS關鍵字或空格來實現。以下是幾種常用的情況:
SELECT column_name AS alias_name
FROM table_name;
SELECT t1.column_name
FROM table_name AS t1;
SELECT t1.column_name, t2.column_name
FROM table_name AS t1
JOIN table_name AS t2 ON t1.id = t2.id;
SELECT alias_name
FROM (SELECT column_name AS alias_name
FROM table_name) AS subquery_alias;
在使用別名時,可以讓查詢結果更易讀,提高代碼的可讀性和可維護性。