Understanding join scenarios with multiple tables?

  • Hi Everyone,

    I have a general question concerning joins. Below is a table scenario that I would like advice on -

    SELECT *

    FROM TABLE_A T0

    INNER JOIN TABLE_B T1 ON T1.[Some_Column] = T0.[Some Column]

    LEFT JOIN TABLE_C T2 ON T2.[Some_Column] = T0.[Some Column]

    Does the above indicate that all records in common between TABLE_A & TABLE_B will be returned, then the records from TABLE_C will be joined to the initial 'result set' (that is the result of joining TABLE_A & TABLE_B), or will TABLE_C simply be joined to TABLE_A regardless of the inner join between TABLE_A & TABLE_B?

    Any help with explaining the processing that goes on in this scenario, and the result set that one would expect to receive will be greatly appreciated.

    Kind Regards,

    David

  • david.dartnell (2/4/2015)


    Hi Everyone,

    I have a general question concerning joins. Below is a table scenario that I would like advice on -

    SELECT *

    FROM TABLE_A T0

    INNER JOIN TABLE_B T1 ON T1.[Some_Column] = T0.[Some Column]

    LEFT JOIN TABLE_C T2 ON T2.[Some_Column] = T0.[Some Column]

    Does the above indicate that all records in common between TABLE_A & TABLE_B will be returned, then the records from TABLE_C will be joined to the initial 'result set' (that is the result of joining TABLE_A & TABLE_B), or will TABLE_C simply be joined to TABLE_A regardless of the inner join between TABLE_A & TABLE_B?

    Any help with explaining the processing that goes on in this scenario, and the result set that one would expect to receive will be greatly appreciated.

    Kind Regards,

    David

    The former, with a notation that what's in A+B doesn't need to find a match in C, in which case T2.[Some_Column] will be NULL.


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply