user3730698
user3730698

Reputation: 19

Left Outer Join Table Ordering

From everything I have learned about LEFT OUTER JOIN, the table you want to be nullable should be on the right side of the equals symbol. If this is the case, why do both of these queries return the same result:

SELECT          *
FROM            employees e
LEFT JOIN       cars c ON c.employeeID=e.id AND c.name='Honda City'
WHERE c.id IS NULL
ORDER BY        e.id ASC;

SELECT          *
FROM            employees e
LEFT JOIN       cars c ON e.id=c.employeeID AND c.name='Honda City'
WHERE c.id IS NULL
ORDER BY        e.id ASC;

Demo: http://sqlfiddle.com/#!15/46d00/2

Upvotes: 1

Views: 178

Answers (1)

mc110
mc110

Reputation: 2833

Q1 uses A LEFT JOIN B ON A.id = B.id

Q2 uses A LEFT JOIN B ON B.id = A.id

You have changed the LHS and RHS of the items being compared in the ON clause, but the LEFT join is talking about which TABLE is on the left.

So to see a difference you would make Q2 use "B LEFT JOIN A ON A.id = B.id"

Upvotes: 5

Related Questions