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 |
|
allan8964
Posting Yak Master
249 Posts |
Posted - 2012-02-29 : 10:30:50
|
| Hi there,A table col has same data like this:ID | Code----------22 | CBD31 | FDC43 | CBD45 | FDCHow can can I find how many rows have same data. I don't mean script like this:select * from table where code = 'CBD'or select * from table where code in ('CBD', 'FDC' ...)I mean sort out all the rows which all have same data.Thanks in advance. |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-02-29 : 10:35:36
|
select t1.* from table t1join (select Code from table group by Code having count(*) > 1)t2on t2.Code = t1.Code No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
allan8964
Posting Yak Master
249 Posts |
Posted - 2012-02-29 : 10:53:17
|
| Thank you soooooooooooooooooo much!!!This is what I need. Thank you!!! |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
|
|
allan8964
Posting Yak Master
249 Posts |
Posted - 2012-02-29 : 11:50:22
|
| Yes, you both are right. Bret's script gives the sum and actually equals the part of webfred's. Pulling out the t2 from webfred and adding count() will get same as Bret's:select Code, Count(Code) As Repeat_Rows from table group by Code having count(*) > 1 |
 |
|
|
|
|
|