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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 CROSS JOIN same as INNER JOIN ON 1 = 1 ??

Author  Topic 

nathans
Aged Yak Warrior

938 Posts

Posted - 2005-01-04 : 14:31:47
Guys,
Im just doing some JOIN exercises. Can we assume that a CROSS JOIN is the same as INNER JOIN ON 1 = 1 in all cases?

Thanks!

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2005-01-04 : 15:29:30
The INNER JOIN ON 1 = 1 will evaluate True for every combination of rows in the two tables. This is the same as a CROSS JOIN. The real question becomes, "Why would you want to do this?"

HTH

=================================================================

Where it is a duty to worship the sun, it is pretty sure to be a crime to examine the laws of heat. -John Morley, statesman and writer (1838-1923)
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2005-01-04 : 15:34:32
Ummm....Dr.?



Brett

8-)
Go to Top of Page

nathans
Aged Yak Warrior

938 Posts

Posted - 2005-01-04 : 15:36:47
I was just trying to understand how the CROSS JOIN functions in comparison to the INNER. I would never use the 1 = 1 syntax.

Thanks HTH
Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2005-01-04 : 15:52:19
Yes, both will produce the "Cartesian product" of the tables involved.

Can also be accomplished with
select * from table1,table2
(which is also a reason not to use that syntax, since you can get "unexpectly large" results)

rockmoose
Go to Top of Page

nathans
Aged Yak Warrior

938 Posts

Posted - 2005-01-04 : 15:58:37
Thanks.

> Ummmm....Dr.?

Brett?

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-01-04 : 16:09:33
Dr. Cross Join:

http://www.sqlteam.com/forums/pop_profile.asp?mode=display&id=6859


Tara
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2005-01-04 : 16:10:35


The Dr.

http://www.sqlteam.com/forums/pop_profile.asp?mode=display&id=6859

Do a search for Cross join on this site...some amazing stuff....



Brett

8-)
Go to Top of Page

nathans
Aged Yak Warrior

938 Posts

Posted - 2005-01-04 : 16:13:38
Thanks all! Ill be sure to read up.

- Nathan
Go to Top of Page

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2005-01-04 : 16:42:05
Nathans,

Remember that the join condition is just an expression that gets evaluated for every combination of rows in the two tables. If it evaluates to true then that combination of rows gets included as part of the join. It's easy to get distracted from this fact since most joins we do are usually some variation of t1.MyKey = t2.YourKey and are almost always based on data within the tables.

Your join predicate of "1 = 1", though academic in nature, is a good example that the join could be anything. This might not seem like a big deal now but it will come in handy when you start working with non-equijoins.

HTH

=================================================================

Where it is a duty to worship the sun, it is pretty sure to be a crime to examine the laws of heat. -John Morley, statesman and writer (1838-1923)
Go to Top of Page

Arnold Fribble
Yak-finder General

1961 Posts

Posted - 2005-01-05 : 07:02:43
T1 FULL OUTER JOIN T2 ON 1 = 0 is fun, though potentially confusing.
Go to Top of Page
   

- Advertisement -