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 |
|
mdhingra01
Posting Yak Master
179 Posts |
Posted - 2005-04-26 : 13:18:15
|
| I need some help with count function.I am counting the number of records that are duplicate in a given table. For this example lets say there are 20 records that have exactly 2 or more records identitcal to it.Is there a query that I can write to give me a result of the number 20.Thanks |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-04-26 : 13:21:44
|
will this do?select count(col1) from MyTablegroup by col1having count(col1) >= 2Go with the flow & have fun! Else fight the flow |
 |
|
|
mdhingra01
Posting Yak Master
179 Posts |
Posted - 2005-04-26 : 13:33:45
|
| No that won't work because that will give me '2' for each record where the record is duplicated in Col 1. Consider the following for col 1:111111222333444555555666666777888888So in this example I want the number that is returned to be 4 becuase there are 4 instances where there is duplicated data. |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-04-26 : 13:36:23
|
select count(*)from(select count(col1) as col1Count from MyTablegroup by col1having count(col1) >= 2) tGo with the flow & have fun! Else fight the flow |
 |
|
|
mdhingra01
Posting Yak Master
179 Posts |
Posted - 2005-04-26 : 13:45:00
|
| I figured out how to do it..Select count(*)from (Select count(col 1)as a from MY TABLE group by col 1 having count(Col_1)>1) as b. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2005-04-26 : 13:54:41
|
does that mean you can read as well? Brett8-) |
 |
|
|
AndyB13
Aged Yak Warrior
583 Posts |
Posted - 2005-04-26 : 14:43:04
|
Hhhhm, plagerism(sp)!Incorrect syntax near........................... Beauty is in the eyes of the beerholder |
 |
|
|
|
|
|