在SQL中,可以使用AS關鍵字為列或表添加別名。別名可以使查詢結果更易于理解和使用。以下是使用別名的語法示例:
SELECT column_name AS alias_name
FROM table_name;
示例:
SELECT first_name AS first, last_name AS last
FROM employees;
SELECT column_name
FROM table_name AS alias_name;
示例:
SELECT e.first_name, e.last_name, d.department_name
FROM employees AS e
JOIN departments AS d ON e.department_id = d.department_id;
在以上示例中,"AS"關鍵字用于為列和表添加別名。通過使用別名,可以簡化查詢語句并使查詢結果更易于理解。