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

Author  Topic 

real_pearl
Posting Yak Master

106 Posts

Posted - 2004-06-18 : 05:25:07
If a table A has

ClassID SectionID
5th A
5th B
5th C
6th A
6th B
6th C

SELECT ClassID, COUNT(ClassID) FROM Class_Section
GROUP BY ClassID

it will return
5th 3
6th 3

There are two classes, how can we get the information telling there is ony one class if only 5th exists even though it contains 10, 20 rows. But the query may return 1 if only 5th exists and if 6th also exists then query return 2 and so on. Please tell me what query should I write to get this information?

ditch
Master Smack Fu Yak Hacker

1466 Posts

Posted - 2004-06-18 : 05:38:40
select count(distinct ClassID)
from Class_Section


Duane.
Go to Top of Page

real_pearl
Posting Yak Master

106 Posts

Posted - 2004-06-18 : 06:21:47
Thanks a lot
Go to Top of Page
   

- Advertisement -