4 ms·
Most of your queries shouldn't be so verbose as to confuse which aliases you are talking about, but I agree - here's the best format :) (because why put ON on a
by hobs 6y ago
Most of your queries shouldn't be so verbose as to confuse which aliases you are talking about, but I agree - here's the best format :) (because why put ON on another line anyway?)
SELECT
bo.title,
au.last_name,
au.first_name
FROM books AS bo
LEFT JOIN authors AS au ON
bo.author_id = au.id
- dragonwriter 6y agoactually, 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
- mulmen 6y agoON should be on another line because it gives context to bo.author_id = au.id.
- hobs 6y agoYou never write NOT ON, so no, I'd disagree that its required for all the inequalities you express.
- mulmen 6y agoHuh? ON is required by the syntax. Why start every line with a keyword that describes the line except the ON portion of a JOIN? It's inconsistent and has no clear benefit.
- deleted 6y ago[deleted]