How to delete "real" duplicates? id | somthing ----------------------- 1 | aaa 1 | aaa 2 | bbb 2 | bbb
(an accident with backup recovery...) Regards, Denis Arh ----- Original Message ----- From: "Franco Bruno Borghesi" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Sunday, June 22, 2003 11:17 PM Subject: Re: [SQL] Delete duplicates > try this > > DELETE FROM aap WHERE id NOT IN ( > SELECT max(id) > FROM aap > GROUP BY keyword > ); > > > > > > > Hi, > > > > I have a table with duplicates and trouble with my SQL. > > I'd like to keep a single record and remove older duplicates. > > For example below of the 6 recods I'd like to keep records > > 4 and 6. > > > > TABLE: aap > > id | keyword > > ----+----------------- > > 1 | LEAGUE PANTHERS > > 2 | LEAGUE PANTHERS > > 3 | LEAGUE PANTHERS > > 4 | LEAGUE PANTHERS > > 5 | LEAGUE BRONCOS > > 6 | LEAGUE BRONCOS > > > > Here is my SQL so far, it will select records 1 to 5 instead > > of 1,2,3 and 5 only. > > > > Any help greatly appreciated. I think I need a Group By somewhere in > > there. > > > > select a1.id > > from aap a1 > > where id < ( SELECT max(id) FROM aap AS a2 ) > > AND EXISTS > > ( > > SELECT * > > FROM aap AS a2 > > WHERE a1.keyword = a2.keyword > > ) > > > > Regards > > Rudi. > > > > ---------------------------(end of > > broadcast)--------------------------- TIP 1: subscribe and unsubscribe > > commands go to [EMAIL PROTECTED] > > > > > ---------------------------(end of broadcast)--------------------------- > TIP 8: explain analyze is your friend > > ---------------------------(end of broadcast)--------------------------- TIP 2: you can get off all lists at once with the unregister command (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])