Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 select from the same table twice using aliases

Author  Topic 

alex100
Starting Member

5 Posts

Posted - 2010-09-18 : 07:30:39
Hi,

when i select from the same table twice(using alases), I get more records than i expected.

why does it occures ?

Regards,
Alex


this is my table -
column_ID
1
2
3


after executing the following query

select T1.column_ID
from table_1 as T1, table_1 as T2


i get those results :
column_ID
1
2
3

1
2
3

1
2
3


webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-09-18 : 07:34:45
You are joining without any condition so each possible pair is created.
It is a cartesian product.
http://en.wikipedia.org/wiki/Cartesian_product


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

alex100
Starting Member

5 Posts

Posted - 2010-09-18 : 07:44:36
Thanks for the answer.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-09-18 : 09:38:04
welcome


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -