I’ve recently discovered that the ON clause of a LEFT JOIN may contain values such as (1 = 1).
This is upsetting to me, as it breaks my perception of how joins function.
I’ve encountered a more elaborate version of the following situation:
SELECT DISTINCT Person.ID, ...
FROM Person LEFT JOIN Manager
ON (Manager.ID = Person.ID OR Manager.ID = -1))
WHERE (...)
It’s perfectly legal. What does “Manager.ID = -1” accomplish, if anything? How can this effect the Join?
If person table is:
If manager table is
if the query is:
Then the result is:
Here all person rows joins with the -1 Admin (on manager table) AND if the same id exist in manager table one more join occurs.