I have code with the following psql
query that I try to understand (It was simplified for the question):
select id, time, t.type, t.sub_type from TABLE_A r,TABLE_B t,TABLE_C l where r.type = t.type and t.type = l.type
Is it the same as doing a join, or am I missing something here?
Advertisement
Answer
You are doing an old school implicit join. This is the syntax used before the ANSI-92 SQL standard which started recommending explicit joins like this version of your query:
select id, time, t.type, t.sub_type -- but please always use aliases here from TABLE_A r inner join TABLE_B t on r.type = t.type inner join TABLE_C l on t.type = l.type;
The above version is considered the “correct” way of expressing your logic. Explicit joins solved a number of problems inherent with implicit joins. Implicit joins place both the join logic and the filter criteria into the same WHERE
clause, potentially making it difficult to tease apart what is happening there. In addition, it was harder to express left/right/inner/cross join using the implicit syntax, with different vendors sometimes having different syntax. The ANSI-92 explicit join is pretty much the same across all the major SQL vendors at this point.