Is it true that no matter which type of join you use, if your WHERE clause checks one table’s pk = other table’s fk, it becomes same as an inner join as far as the result set is conncerned? In other words, if your sql query has some stuff like:
“Select … from A Left join B On (…) E, F Full Outer Join G on (A.pk = G.fk) … WHERE A.pk = G.fk and A.pk = B.fk and etc…”
In the above query, A is left-joined to B, whereas G is outer-joined to A on its fk. But as the where clause has the two checks, so the whole query reduces to something like:
“Select … from A INNER JOIN B On (…) E, F INNER Join G on (A.pk = G.fk) … WHERE etc …”
?
The reason for asking this query is that I have many cartesian-type joins along with where clauses that are on one table’s pk = other table’s fk, that are slowing the query down. I was thinking of replacing the cartesian products with either Left Joins combined with keeping all the where clauses, or all Inner Joins.
Yes if you refernce the right side of a left outer join in a where clause with anything except “where myfield is null”, you have created an inner join. This is because it filters out anything that that doesn’t meet that condition including all the records that don’t have a match to the intial table. Same with the other non-inner joins. To get around it you put the condition in the join. Example (this turns it into an inner join):
Rewritten to preserve the left join:
I also want to comment on something you said in a comment but figured my response would be too long for another comment.
“Select … From A Inner Join B on (A.id = B.a_id),C,D, F where A.id=F.id”
to: “Select … From A Inner Join B on (A.id = B.a_id),C,D INNER JOIN F on A.id = F.a_id”
You do not want to combine syntaxes like this; this becomes very hard to maintain. In fact I recommend never using the old style comma syntax as it is subject to accidental cross joins. So in your example I would write to get the result set you currently get (at least someone maintaining will know you indended a cross join instead of did it by accident):
Altenatively if the cross join is accidental, the code would change to: