all groups > sql server mseq > august 2005 >
You're in the

sql server mseq

group:

Find Duplicate Data



Find Duplicate Data Travis
8/3/2005 12:23:02 AM
sql server mseq: Hi ,

Can someone help me to build a query base on :
SELECT Full_Name,FLT_ID, FLT_DT_ID,PNR_ID

Where Full_Name,FLT_ID, FLT_DT_ID is duplicate in the same table

Thank You very much
--
Re: Find Duplicate Data Hugo Kornelis
8/3/2005 9:56:00 PM
[quoted text, click to view]

SELECT a.Full_Name, a.FLT_ID, a.FLT_FT_ID, a.PNR_ID
FROM MyTable AS a
INNER JOIN MyTable AS b
ON b.Full_Name = a.Full_Name
AND b.FLT_ID = a.FLT_ID
AND b.FLT_FT_ID = a.FLT_FT_ID
AND b.PNR_ID <> a.PNR_ID

or

SELECT a.Full_Name, a.FLT_ID, a.FLT_FT_ID, a.PNR_ID
FROM MyTable AS a
WHERE EXISTS
(SELECT *
FROM MyTable AS b
WHERE b.Full_Name = a.Full_Name
AND b.FLT_ID = a.FLT_ID
AND b.FLT_FT_ID = a.FLT_FT_ID
AND b.PNR_ID <> a.PNR_ID)

or

SELECT a.Full_Name, a.FLT_ID, a.FLT_FT_ID, a.PNR_ID
FROM MyTable AS a
INNER JOIN (SELECT Full_Name, FLT_ID, FLT_FT_ID
FROM MyTable
GROUP BY Full_Name, FLT_ID, FLT_FT_ID
HAVING COUNT(*) > 1) AS b
ON b.Full_Name = a.Full_Name
AND b.FLT_ID = a.FLT_ID
AND b.FLT_FT_ID = a.FLT_FT_ID

Try them all in your database to see which one gives the best
performance.

Disclaimer: All queries above are untested, since you didn't provide
CREATE TABLE and INSERT statements to test them on.

Best, Hugo
--

AddThis Social Bookmark Button