If you use a LEFT JOIN and also have a WHERE clause, are all the conditions in the WHERE clause being disregarded if the table that you tried to join does not exist?
In other words, do I have to specifically compare against the id from the LEFT JOIN?
SELECT distinct(watchedItems.id)
FROM globalItems, watchedItems
LEFT JOIN bidGroups ON bidGroups.bidGroupID = watchedItems.bidGroupID
WHERE
watchedItems.aid = globalItems.aid
AND watchedItems.processRunning = 0
(watchedItems.bidGroupID IS NULL
OR (watchedItems.bidGroupID IS NOT NULL AND bidGroups.bidGroupQty > 0))
Could I write instead of the entire last bit just
AND bidGroups.bidGroupQty > 0
and it will not be tested because bidGroups does not exist if the LEFT JOIN fails? I know that without the LEFT JOIN it will definitely test against it all the time, which means if this test fails, the entire statement is not executed. But I want it to be executed in any case (with and without bidGroups.)
If the table doesn’t exist your statement won’t parse and will result in a SQL exception.EDIT
I’d write your query this way, for readability:
The answer to whether you need to check
watchedItems.bigGroupID IS NOT NULLis no, you do not have to as the join condition already covers that.