3 ms·
This is how I write SQL: select col1 ,col2 ,col3 from table1 a left join table 2 b on a.col1 = b.col2 where 1=1 and col1 = '
by jgilfillan 10y ago
This is how I write SQL:
select
col1
,col2
,col3
from table1 a
left join table 2 b
on a.col1 = b.col2
where 1=1
and col1 = 'condition'
and col2 = 'condition2'
;
* everything lower case (except strings)
* leading commas
* conditions indented by two spaces
* select columns indented by two spaces, except the first colunm which is indented by three.
* where 1=1 for easier commenting/uncommenting of conditions
- zikzak 10y agoCame here to find out who else uses leading commas. I learned this several years ago at my current job and love it. I find it much more readable and also makes adding to the list clearer for some reason. Plus if you ever need to insert like 50 commas at the start of a bunch of lines in an ad hoc query it is much easier at the start of the line (yes, I am an animal).