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
 COUNT(*) with a JOIN??

Author  Topic 

dbusher
Starting Member

7 Posts

Posted - 2007-03-09 : 14:19:30
I am a newbie..and here is my newbie question

I have 2 tables : table1 and table2

SELECT table1.cache_type, table2.log_owner_id
FROM table1, table2
WHERE table1.cache_id = table2.cache_id and table2.log_owner_id=62 and table1.cache_type = "traditional"

This returns 10 rows. But what I would like to do is return the total number of rows..the COUNT.

I tried the following but that does not work:
SELECT COUNT(*) table1.cache_type, table2.log_owner_id
FROM table1, table2
WHERE table1.cache_id = table2.cache_id and table2.log_owner_id=62 and table1.cache_type = "traditional"

any help would be greatly appreciated! thx

DustinMichaels
Constraint Violating Yak Guru

464 Posts

Posted - 2007-03-09 : 14:29:20
Try using a group by statement.

SELECT COUNT(*) table1.cache_type, table2.log_owner_id
FROM table1, table2
WHERE table1.cache_id = table2.cache_id and table2.log_owner_id=62 and table1.cache_type = "traditional"
GROUP BY table1.cache_type, table2.log_owner_id
Go to Top of Page

DustinMichaels
Constraint Violating Yak Guru

464 Posts

Posted - 2007-03-09 : 14:30:21
Err oops I misread your post, just use COUNT(*) in the select statement.


SELECT COUNT(*)
FROM table1, table2
WHERE table1.cache_id = table2.cache_id and table2.log_owner_id=62 and table1.cache_type = "traditional"


Go to Top of Page

dbusher
Starting Member

7 Posts

Posted - 2007-03-09 : 14:58:10
wow..thanks for the prompt response..I will give this a try.
Go to Top of Page
   

- Advertisement -