4 ms·
This is my favorite guide yet! My syntax, like others, is a little different (lowercase, 2 spaces, commas-first, bracket quotes, ons right under joins w/ joine
by arh68 7y ago
This is my favorite guide yet!
My syntax, like others, is a little different (lowercase, 2 spaces, commas-first, bracket quotes, ons right under joins w/ joined table on LHS, left joins left-aligned): (this query isn't supposed to make sense)
select
u.id [user]
, u.email [email]
, o.name [office]
, sum(t.id) [# things]
from main_tblusers_db u
inner join tbloffices_db o
on o.id = u.office_id
inner join things_tbl t
on t.user_id = u.id
left join example e
on e.user_id = u.id
where
u.deleted is null
and (
u.active is not null
or u.special = 1
)
group by
u.id -- the 1, 2 syntax is new to me!
, u.email
, o.name
- gwillz 7y agoWell this might be an interesting discussion to read for you. Take what you will from it. https://gist.github.com/isaacs/357981 https://gist.github.com/isaacs/357981
- lazzlazzlazz 7y agoFor the record, this syntax is horrific and almost unreadable to my eyes. Multiple spaces after `LEFT` in `LEFT JOIN`? Just to stick with "river"-style alignment, yet your outer-level keywords (`SELECT`, `FROM`, etc.) aren't aligned? It's difficult to understand why one would pick this format.
- arh68 7y agoWell how far do you go with the river? Aligning with select means group by sticks out. Aligning with group by means left join sticks out. Aligning with left join means inner join sticks out. EDIT: feel free to show me something better..
- lazzlazzlazz 7y ago`GROUP BY` you align with the space between `GROUP` and `BY`. `INNER JOIN` goes fully on the right side of the river. The guide at https://www.sqlstyle.guide/ https://www.sqlstyle.guide/ is almost perfect.