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.
| Author |
Topic |
|
Mondeo
Constraint Violating Yak Guru
287 Posts |
Posted - 2008-05-14 : 09:44:58
|
| I know this is simple but my minds gone blankid desc12345 Item 112345 Item 212346 Item 312346 Item 412347 Item 5I want to count all the distinct ID's, so for the results here I needid count12345 212346 212347 1Thanks |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2008-05-14 : 09:49:50
|
| select id ,count(*) from table group by id |
 |
|
|
Mondeo
Constraint Violating Yak Guru
287 Posts |
Posted - 2008-05-14 : 09:55:04
|
| Thanks,Just taking it one step further I tried thisSELECT CapID, COUNT(*) AS cFROM tblNewMatrixLombardWHERE (c > 1)GROUP BY CapIDIt says invalid column name c - can I fix this?Thanks |
 |
|
|
bjoerns
Posting Yak Master
154 Posts |
Posted - 2008-05-14 : 11:04:11
|
| that's what HAVING is for. WHERE affects the data before it is grouped. |
 |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2008-05-14 : 11:43:10
|
| Am sorry,SELECT CapID, COUNT(*) AS cFROM tblNewMatrixLombardhaving (COUNT(*) > 1)GROUP BY CapID |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-14 : 11:53:17
|
quote: Originally posted by sakets_2000 Am sorry,SELECT CapID, COUNT(*) AS cFROM tblNewMatrixLombardhaving (COUNT(*) > 1)GROUP BY CapIDhaving (COUNT(*) > 1)
|
 |
|
|
|
|
|