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)
 count on sever tables

Author  Topic 

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2005-10-27 : 09:54:06
i have a main table with users with there each unique id fo exampe like passport number.
now i have 3 other tables in which each table hold for the unique user
few rows with details!
in table a : there are 3 rows
in table b : there are 8 rows
in table c : there are 0 rows
i want to make a select which give me few field from the main table
and the count(table a),count(table b),count(table c)
how can i do this?
beaucse i tried to do it with inner join
and i got on all 3 count if based on the about data the value 8!!!!
why is that?
thnaks i nadvance
peleg

Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2005-10-27 : 10:04:08
The Count will display the total number of number of records which your select query produced.

Complicated things can be done by simple thinking
Go to Top of Page

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2005-10-27 : 10:12:26
can u help o not?

Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-10-27 : 11:03:30
use left join instead of inner join.

use northwind
select count(distinct o.orderid), count(od.orderid)
from orders O
left join [Order details] OD on O.orderid = OD.orderId


Go with the flow & have fun! Else fight the flow
Go to Top of Page
   

- Advertisement -