Delete duplicate enties

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
leewad
Forum Commoner
Posts: 91
Joined: Tue May 11, 2004 8:32 am

Delete duplicate enties

Post by leewad »

Hi

how can I delete duplicate entries from a mysql database? The query to display them I have is:

Code: Select all

SELECT 
DISTINCT url, COUNT( url ) AS qty 
FROM 
table 
GROUP BY 1 HAVING qty > 1
But how can I delete them?

Many thanks
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post by dibyendrah »

Dear leewad,

Have a look at this solution .
Create a new table with just distinct entries?

Code: Select all

CREATE new_tbl SELECT id, url
FROM old_tbl
GROUP BY url;
This will create a new table with just the distinct URLs.

Dibyendra
Post Reply