|
Home > Archive > MS SQL Server MSEQ > August 2005 > Find Duplicate Data
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Find Duplicate Data
|
|
| Travis 2005-08-03, 3:23 am |
| 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
--
Travis Tan
| |
| Hugo Kornelis 2005-08-03, 8:24 pm |
| On Wed, 3 Aug 2005 00:23:02 -0700, Travis wrote:
>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
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
--
(Remove _NO_ and _SPAM_ to get my e-mail address)
|
|
|
|
|