在MySQL中使用別名(alias)可以通過(guò)AS關(guān)鍵字或空格來(lái)實(shí)現(xiàn)。以下是幾種常用的情況:
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;
在使用別名時(shí),可以讓查詢(xún)結(jié)果更易讀,提高代碼的可讀性和可維護(hù)性。