Re: Find Duplicate Data
- From: Hugo Kornelis <hugo@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 03 Aug 2005 21:56:00 +0200
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)
.
- References:
- Find Duplicate Data
- From: Travis
- Find Duplicate Data
- Prev by Date: Find Duplicate Data
- Next by Date: Extracting Latest Date
- Previous by thread: Find Duplicate Data
- Next by thread: Find Duplicate Data
- Index(es):
Relevant Pages
|
|