SQL Happiness

Hello SQLer's out there.

Here's a little nugget for you.  Use the join syntax.  Why?  Because it becomes super obvious what parts of the SQL is for a JOIN and what parts are for a filter.

Here's what I mean

select blah
from blah1 a, blah2 b, blah3 c, etc.
where a.field = b.field 
and a.other like 'ABC%'
and b.field = c.field

In a big SQL with more tables and more fields, you start to loose the distinction between join and filter parts of the SQL.

This is better:


select blah
from blah1 a 
inner join blah2 b on (a.field = b.field), 
inner join blah3 c on (b.field = c.field), etc.
where a.other like 'ABC%'

Don't you agree?

I made this post because I have a 20 line SQL with a filter clause hidden among the join clauses.  This is better practice.



Comments

Popular Posts