I have a question about using three joins between 3 tables. Changing the type of JOIN between second and third tables, the result changes and I don't understand why.
TABLE1 NAME AND AGE
NAME | AGE |
---|---|
BILL | 20 |
JOHN | 25 |
MARTHA | 34 |
STEVE | 40 |
EMILY | 30 |
TABLE2 NAME AND ID
NAME | ID |
---|---|
BILL | 001S |
JOHN | 002B |
MARTHA | 001Z |
TABLE3 ID AND HOBBIES
ID | HOBBIES |
---|---|
001S | FOOTBALL |
002B | MUSIC |
001Z | VOLLEYBALL |
EXAMPLE1
SELECT NAME, HOBBIES
FROM TABLE1
LEFT JOIN TABLE2 ON TABLE1.NAME = TABLE2.NAME
LEFT JOIN TABLE3 ON TABLE2.ID = TABLE3.ID
EXAMPLE2
SELECT NAME, HOBBIES
FROM TABLE1
LEFT JOIN TABLE2 ON TABLE1.NAME = TABLE2.NAME
INNER JOIN TABLE3 ON TABLE2.ID = TABLE3.ID
I want all the NAMES, no matter if they have HOBBIES or not. And this only happens in EXAMPLE1, in EXAMPLE2 the query returns the NAMES with HOBBIES, but I can't understand why it's not working with EXAMPLE2. The only difference is the INNER and that does not affect the relationship between table 1 and 2.
Where am I going wrong?