I have a multiple JOIN in the form of
SELECT * FROM column1
LEFT JOIN column2 USING(id)
JOIN column3 USING(name)
JOIN column4 USING(info)
WHERE column1.id = 44
If changing the LEFT JOIN to JOIN; for obvious reason, the query will return nothing in the absence of column2.id. The main data is column1 and the others are supportive data; thus, I want to retrieve data just if column1.id exists.
My question is: Does the first LEFT JOIN guarantees the query to return column1 values where column1.id exists, regardless of subsequent JOINs (e.g. when column3.name does not exist)? Or I need to change the next (all) JOINs to LEFT JOIN too?
You have a few options as the direct answer to your question is
no.Change all subsequent joins to LEFT JOINs.
If possible, re-arrange the query…
Or…
On a side note, I’d avoid natural joins and the
USINGsyntax. The logic is less transparent, it’s more open to bugs, more open to break later (if you add a field to one of the tables duplicating a field in the USING option), etc, etc.