0

Possible Duplicate:
SQL - How can I remove duplicate rows?

Hello all

How I can Write following query .

I have a table Trace and I want to get all lines there where ID columns and MC columns combinations are appear more then once.

for example all lines where ID = 2 and MC = 11 appear more then once .

Thanks

Community
  • 1
  • 1
Night Walker
  • 20,638
  • 52
  • 151
  • 228
  • 1
    Asked many many times before. http://www.google.co.uk/search?sourceid=chrome&ie=UTF-8&q=site%3Astackoverflow.com+find+duplicates+database – Oded May 18 '11 at 12:15

2 Answers2

1

You could group on ID, MC, and use having to select combinations that occur more than once:

select  ID
,       MC
from    Trace
group by
        ID
,       MC
having  count(*) > 1
Andomar
  • 232,371
  • 49
  • 380
  • 404
0
SELECT *
FROM Trace T1
INNER JOIN (
  SELECT ID, MC
  FROM Trace T2
  GROUP BY ID, MC
  HAVING COUNT(*) > 1
) T22
ON T22.ID = T1.ID
AND T22.MC = T1.MC
Will A
  • 24,780
  • 5
  • 50
  • 61