Page 1 of 1

How to delete duplicate records in MYSQL with PHP.

Posted: Tue Mar 16, 2004 3:04 pm
by dmacman1962
Hi everyone,

I have a simple MYSQL table with about 4000 records. The only field is category. The data is category types, IE: restaurants, hairdressers, car dealers, etc. There are alot of duplicates and a lot of unique entries.

I have searched the web and here for about 2 hours on a simple way to either delete the duplicates, and leave an original. Or, create a new table from the existing one and only get unique entries.

I don't know quite how to do this. Any direction would be greatly appreciated.

Thanks in advance,

Dmacman

Re: How to delete duplicate records.

Posted: Tue Mar 16, 2004 3:11 pm
by TheBentinel.com
dmacman1962 wrote:Hi everyone,

I have a simple table with about 4000 records. The only field is category. The data is category types, IE: restaurants, hairdressers, car dealers, etc. There are alot of duplicates and a lot of unique entries.

I have searched the web and here for about 2 hours on a simple way to either delete the duplicates, and leave an original. Or, create a new table from the existing one and only get unique entries.

I don't know quite how to do this. Any direction would be greatly appreciated.

Thanks in advance,

Dmacman
There's a DISTINCT clause in SQL, does your database support it?

SELECT DISTINCT * FROM YourTable

It will return only the unique entries.

Hope it helps!

Posted: Wed Mar 17, 2004 7:59 am
by JAM
As mentioned, 'select distinct ...' would make only, well, distinct searches.

If you have an issue with the multible data you could dublicate the table structure then do a:

Code: Select all

insert into newtable
select distinct * from oldtable
...and voilá, a fresh start.