Click to See Complete Forum and Search --> : Duplicate Records was wondering


realtime158
01-19-2007, 10:41 AM
Here is a SQL statement that will count all the duplicate instances of the title

SELECT SID,title,
COUNT(title) AS NumOccurrences
FROM savedsearche where post_id <> ''
GROUP BY title
HAVING ( COUNT(title) > 1 ) order by NumOccurrences desc

Now what i want to do is move all the duplicated instances to another table but keep only one
instance of the record in table where the duplicateds were found. How would you do this using mySQL

Thanks...

chazzy
01-19-2007, 02:16 PM
is there any date/time field showing which was inserted first?

realtime158
01-19-2007, 04:39 PM
Yes there is a data the field is called datecreated

Thanks...

chazzy
01-19-2007, 07:10 PM
select * from table a WHERE datecreated != (select max(datecreated) from table WHERE title = a.title)

What this does is select all columns of all items in a table that don't have the max value of datecreated.

realtime158
01-22-2007, 08:57 AM
I am not using mySQL 5.X but only 4.0.27-standard. This statment will not work.

Thanks...

chazzy
01-22-2007, 03:47 PM
convert it to an outer join, should work the same.

realtime158
01-23-2007, 04:41 PM
select * from table a WHERE datecreated != (select max(datecreated) from table WHERE title = a.title)

So how would you do that because the data is coming form the same table.