|
|
|
|
|
by dragonwriter
1890 days ago
|
|
actually, I'd say the best is “column aliases are like full identifiers that name what the entity is in the context of the query”. In simple cases that may be just the singular of the table name, e.g.: SELECT
book.title,
author.last_name,
author.first_name
FROM books AS book
LEFT JOIN authors AS author ON
book.author_id = author.id
But in other cases, it will be different, e.g.: SELECT
manager.last_name || ', ' || manager.first_name AS manager_name,
coalesce(employee.title, 'All Titles') AS staff_title,
count(employee.id) AS count
FROM employees AS manager
LEFT JOIN employees AS employee ON
manager.id = employee.manager_id
GROUP BY manager.id, ROLLUP(employee.title)
HAVING employee.title IS NOT NULL
OR GROUPING(employee.title)=1
|
|