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
 about "count"

Author  Topic 

smile
Starting Member

22 Posts

Posted - 2009-03-15 : 17:26:36
Hello again!

Here's my question: let's say I have two tables - t1 and t2, and the query "select count(*) from t1 " returns 9, and "select count(*) from t2" returns 8. The why the query "select count(*) from t1,t2" returns 72? I see that the two results are multiplied but I don't get why...? So it does something like Cartesian product?

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2009-03-15 : 18:02:07
yes
select count(*) from t1,t2

creates a cross join between t1 and t2 which is the same as a cartesian product


___________________________________________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.5 out!
Go to Top of Page

smile
Starting Member

22 Posts

Posted - 2009-03-15 : 18:14:07
Ok, thanks!
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-03-16 : 00:11:47

If you want the count as t1 by joining t2

The query seems like

Select count(a.*) from t1 a,t2 b where a.id=b.id

Regards

Senthil.C
Willing to update...
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-16 : 11:34:16
staring from sql 2005, you should busing new join syntax instead of below syntax as this wont be supported in future version of sql.
Go to Top of Page
   

- Advertisement -