SQL Command need help! [message #371000] |
Thu, 03 August 2000 11:58 |
Jovi
Messages: 1 Registered: August 2000
|
Junior Member |
|
|
SQL Server 7.0
Table
ID Subject
========
1 A
2 C
3 A
4 B
5 D
6 B
How to Select Like this:
(Order By ID)
ID Subject Count
=============
1 A 2
2 C 1
4 B 2
5 D 1
|
|
|
|
Re: SQL Command need help! [message #371007 is a reply to message #371000] |
Sat, 05 August 2000 16:31 |
Vjeko
Messages: 15 Registered: August 2000
|
Junior Member |
|
|
I think this statement will work fine:
SELECT t1.Id,t1.Subject,t2.number_of_subjects
FROM Table t1,(select t.Subject,count(*) number_of_subjects from Table t group by t.Subject) t2
WHERE t1.Subject=t2.Subject and t1.Id in (select min(id) from Table group by Subject)
ORDER BY t1.Id;
|
|
|