Why this uses two different aliases for the same table?

Hello

Regarding the statement below, can you explain why would it be needed to use two aliases for the same table?

FROM [Table1] p
LEFT JOIN [Table2] c on c.[Col1] = p.Col2
LEFT JOIN [Table2] cc on cc.[Col1] = p.Col3

Thanks!

Sounds like homework. Please researxh the word alias

My point is why not do:

FROM [Table1] p
LEFT JOIN [Table2] c on c.[Col1] = p.Col2
LEFT JOIN c on c.[Col1] = p.Col3

Because you cant in ms sql

Oh I see. So, in the resulting table, will c.[Col2] be different to cc.[Col2]? Or they will be exactly the same and they can be used interchangeably?

hi

the way to do this is

FROM [Table1] p
LEFT JOIN [Table2] c on c.[Col1] = p.Col2
LEFT JOIN c on c.[Col1] = p.Col3


FROM [Table1] p
LEFT JOIN [Table2] c on c.[Col1] = p.Col2 OR  on c.[Col1] = p.Col3

Thanks!
Will they produce the same results of the first will potentially produce duplicates while the second won't?

We can do some TESTING with sample data to find out

mind you .. there is a type of mental fallacy .. the test results will be what you expect BUT not for the reasons
you think ..so in other scenarios MAY give error

These scenarios are what I am worried about, can you elaborate when it will give errors?
Thanks!

One Scenario .. name is not an exact match

please google search for SQL Data Anamolies

1 Like