November 6, 2018 at 10:21 pm
Comments posted to this topic are about the item Mixed Joins
November 6, 2018 at 10:24 pm
Nice question, thanks Ben
Trying to explain this to the uninitiated is not simple....
____________________________________________
Space, the final frontier? not any more...
All limits henceforth are self-imposed.
“libera tute vulgaris ex”
November 7, 2018 at 2:59 am
Definitely a good question! I've seen lots of people query this behaviour. And then trying to explain to them how to "fix" it to get what they intended....
November 7, 2018 at 3:04 am
Of course, in a case sensitive database, the answer is "none of the above". table_a <> Table_a <> TABLE_A.
November 7, 2018 at 3:36 am
Force the join between B and C to take place first, and you change the result:
SELECT *
FROM TABLE_A
LEFT JOIN TABLE_B
INNER JOIN TABLE_C
ON TABLE_B.ID = TABLE_C.ID
ON TABLE_A.ID = TABLE_B.ID;
-- 3 rows
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
November 7, 2018 at 3:50 am
ChrisM@Work - Wednesday, November 7, 2018 3:36 AMForce the join between B and C to take place first, and you change the result:
SELECT *
FROM TABLE_A
LEFT JOIN TABLE_B
INNER JOIN TABLE_C
ON TABLE_B.ID = TABLE_C.ID
ON TABLE_A.ID = TABLE_B.ID;
-- 3 rows
I get what you're saying, but wouldn't it be clearer to left join to C?
November 7, 2018 at 3:57 am
call.copse - Wednesday, November 7, 2018 3:50 AMChrisM@Work - Wednesday, November 7, 2018 3:36 AMForce the join between B and C to take place first, and you change the result:
SELECT *
FROM TABLE_A
LEFT JOIN TABLE_B
INNER JOIN TABLE_C
ON TABLE_B.ID = TABLE_C.ID
ON TABLE_A.ID = TABLE_B.ID;
-- 3 rowsI get what you're saying, but wouldn't it be clearer to left join to C?
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
November 7, 2018 at 4:32 am
ChrisM@Work - Wednesday, November 7, 2018 3:36 AMForce the join between B and C to take place first, and you change the result:
SELECT *
FROM TABLE_A
LEFT JOIN TABLE_B
INNER JOIN TABLE_C
ON TABLE_B.ID = TABLE_C.ID
ON TABLE_A.ID = TABLE_B.ID;
-- 3 rows
Thanks! That is what I'm searching for!
November 7, 2018 at 4:35 am
Carlo Romagnano - Wednesday, November 7, 2018 4:32 AMChrisM@Work - Wednesday, November 7, 2018 3:36 AMForce the join between B and C to take place first, and you change the result:
SELECT *
FROM TABLE_A
LEFT JOIN TABLE_B
INNER JOIN TABLE_C
ON TABLE_B.ID = TABLE_C.ID
ON TABLE_A.ID = TABLE_B.ID;
-- 3 rowsThanks! That is what I'm searching for!
You're welcome. There's a little more info and a better example here.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
November 7, 2018 at 8:27 am
nice and simple,
ta
---------------------------------------------------------------------------------------
The more you know, the more you know that you dont know
November 8, 2018 at 2:43 am
ChrisM@Work - Wednesday, November 7, 2018 3:57 AMcall.copse - Wednesday, November 7, 2018 3:50 AMChrisM@Work - Wednesday, November 7, 2018 3:36 AMForce the join between B and C to take place first, and you change the result:
SELECT *
FROM TABLE_A
LEFT JOIN TABLE_B
INNER JOIN TABLE_C
ON TABLE_B.ID = TABLE_C.ID
ON TABLE_A.ID = TABLE_B.ID;
-- 3 rowsI get what you're saying, but wouldn't it be clearer to left join to C?
No, because the queries are not logically equivalent:
SELECT *
FROM TABLE_A
LEFT JOIN TABLE_B
INNER JOIN TABLE_C
ON TABLE_B.ID = TABLE_C.ID
ON TABLE_A.ID = TABLE_B.ID;SELECT *
FROM TABLE_A
LEFT JOIN TABLE_B
ON TABLE_A.ID = TABLE_B.ID
left JOIN TABLE_C
ON TABLE_B.ID = TABLE_C.ID
I read the link you posted below and now consider myself elucidated, thank you. After all these years there is plenty to learn even on relatively basic querying!
November 8, 2018 at 4:23 am
Nice one Ben..
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply