<?xml version="1.0" encoding="UTF-8"?><rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
> <channel><title>Comments on: Mysql Remove Duplicate Data or Rows With DISTINCT</title> <atom:link href="http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/feed/" rel="self" type="application/rss+xml" /><link>http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/</link> <description>Every answer asks a more beautiful question.</description> <lastBuildDate>Fri, 10 Feb 2012 19:55:56 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>By: Chicago Web</title><link>http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-67021</link> <dc:creator>Chicago Web</dc:creator> <pubDate>Tue, 17 Jan 2012 03:26:56 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-67021</guid> <description>Here is a much faster solution for large tables.... The other methods will take hours on a very large table.
First we make a new table with distinct values for the field we are trying to remove duplicates for.
CREATE TABLE new_table as
SELECT * FROM old_table WHERE 1 GROUP BY column_to_remove_duplicates;
Step 2: remove old table
DROP TABLE old_table;
Step 3: mv the new table back to the old one
RENAME TABLE new_table TO old_table;
Done!</description> <content:encoded><![CDATA[<p>Here is a much faster solution for large tables&#8230;. The other methods will take hours on a very large table.</p><p>First we make a new table with distinct values for the field we are trying to remove duplicates for.</p><p>CREATE TABLE new_table as<br
/> SELECT * FROM old_table WHERE 1 GROUP BY column_to_remove_duplicates;</p><p>Step 2: remove old table</p><p>DROP TABLE old_table;</p><p>Step 3: mv the new table back to the old one</p><p>RENAME TABLE new_table TO old_table;</p><p>Done!</p> ]]></content:encoded> </item> <item><title>By: neeraj</title><link>http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-66952</link> <dc:creator>neeraj</dc:creator> <pubDate>Mon, 16 Jan 2012 08:16:40 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-66952</guid> <description>I like to below query if there is need to remove duplicate rows of table that does not contain primary key:
DELETE FROM items WHERE GREATEST(0,@num := IF(NAME = @NAME, @num + 1, 0),LEAST(0, LENGTH(@NAME := NAME)))&gt;0
In my example items table just has one column &quot;name&quot; and above query removes the duplicate rows</description> <content:encoded><![CDATA[<p>I like to below query if there is need to remove duplicate rows of table that does not contain primary key:</p><p>DELETE FROM items WHERE GREATEST(0,@num := IF(NAME = @NAME, @num + 1, 0),LEAST(0, LENGTH(@NAME := NAME)))&gt;0</p><p>In my example items table just has one column &#8220;name&#8221; and above query removes the duplicate rows</p> ]]></content:encoded> </item> <item><title>By: Shairyar</title><link>http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-66165</link> <dc:creator>Shairyar</dc:creator> <pubDate>Thu, 29 Dec 2011 09:07:16 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-66165</guid> <description>great thanks, exactly what i was looking for.</description> <content:encoded><![CDATA[<p>great thanks, exactly what i was looking for.</p> ]]></content:encoded> </item> <item><title>By: John Ortiz</title><link>http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-65919</link> <dc:creator>John Ortiz</dc:creator> <pubDate>Thu, 22 Dec 2011 14:56:59 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-65919</guid> <description>Thanks a lot for this mini-guide. It was useful for me.</description> <content:encoded><![CDATA[<p>Thanks a lot for this mini-guide. It was useful for me.</p> ]]></content:encoded> </item> <item><title>By: bob</title><link>http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-65565</link> <dc:creator>bob</dc:creator> <pubDate>Tue, 13 Dec 2011 05:19:06 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-65565</guid> <description>&lt;pre&gt;
DELETE FROM table
WHERE ID NOT IN (SELECT *
FROM (SELECT MIN(n.ID)
FROM table n
GROUP BY n.FIELDNAME) x)
&lt;/pre&gt;</description> <content:encoded><![CDATA[<pre>
DELETE FROM table
 WHERE ID NOT IN (SELECT *
                    FROM (SELECT MIN(n.ID)
                            FROM table n
                        GROUP BY n.FIELDNAME) x)
</pre>]]></content:encoded> </item> <item><title>By: John Komla</title><link>http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-65317</link> <dc:creator>John Komla</dc:creator> <pubDate>Thu, 08 Dec 2011 12:17:10 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-65317</guid> <description>This saved my day. I even customized this to fit my project, as different users insert into that same table, only records attached to a particular logging session are removed from the table.
This works great !
Thank you again !</description> <content:encoded><![CDATA[<p>This saved my day. I even customized this to fit my project, as different users insert into that same table, only records attached to a particular logging session are removed from the table.</p><p>This works great !</p><p>Thank you again !</p> ]]></content:encoded> </item> <item><title>By: ganesh</title><link>http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-65063</link> <dc:creator>ganesh</dc:creator> <pubDate>Fri, 02 Dec 2011 05:54:03 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-65063</guid> <description>hey guys  this work thanks...........</description> <content:encoded><![CDATA[<p>hey guys  this work thanks&#8230;&#8230;&#8230;..</p> ]]></content:encoded> </item> <item><title>By: kaushik</title><link>http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-65029</link> <dc:creator>kaushik</dc:creator> <pubDate>Thu, 01 Dec 2011 09:24:46 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-65029</guid> <description>thanx jafar..that is gr8 man..:)</description> <content:encoded><![CDATA[<p>thanx jafar..that is gr8 man..:)</p> ]]></content:encoded> </item> <item><title>By: Afshin</title><link>http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-64553</link> <dc:creator>Afshin</dc:creator> <pubDate>Thu, 17 Nov 2011 21:07:51 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-64553</guid> <description>All of you assume that there is a unique ID or we can create a new table!
Let&#039;s say there is no ID and there is just one or two columns, and we don&#039;t want to create a new table!
any idea?</description> <content:encoded><![CDATA[<p>All of you assume that there is a unique ID or we can create a new table!<br
/> Let&#8217;s say there is no ID and there is just one or two columns, and we don&#8217;t want to create a new table!</p><p>any idea?</p> ]]></content:encoded> </item> <item><title>By: sane</title><link>http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-64302</link> <dc:creator>sane</dc:creator> <pubDate>Thu, 10 Nov 2011 11:31:26 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-64302</guid> <description>!!!!!   I need synatax in mysql !!!!!!
i create a table called studentaccount
if i create a row at the end one column called &quot;status&quot; should hav value boolean value as true
if i delete a row the status should be false
what is the syntax plzzzz help me</description> <content:encoded><![CDATA[<p>!!!!!   I need synatax in mysql !!!!!!</p><p>i create a table called studentaccount<br
/> if i create a row at the end one column called &#8220;status&#8221; should hav value boolean value as true</p><p>if i delete a row the status should be false</p><p>what is the syntax plzzzz help me</p> ]]></content:encoded> </item> <item><title>By: vikingu</title><link>http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-63467</link> <dc:creator>vikingu</dc:creator> <pubDate>Thu, 13 Oct 2011 10:16:17 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-63467</guid> <description>i&#039;ll test at first, but looks like should workout!!</description> <content:encoded><![CDATA[<p>i&#8217;ll test at first, but looks like should workout!!</p> ]]></content:encoded> </item> <item><title>By: manish</title><link>http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-62128</link> <dc:creator>manish</dc:creator> <pubDate>Sun, 04 Sep 2011 04:51:36 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-62128</guid> <description>thank you  jafar bhayi .</description> <content:encoded><![CDATA[<p>thank you  jafar bhayi .</p> ]]></content:encoded> </item> <item><title>By: MANNULAL</title><link>http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-61914</link> <dc:creator>MANNULAL</dc:creator> <pubDate>Fri, 26 Aug 2011 13:32:21 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-61914</guid> <description>IT IS THE WAY OF  HELPING EACH OTHER</description> <content:encoded><![CDATA[<p>IT IS THE WAY OF  HELPING EACH OTHER</p> ]]></content:encoded> </item> <item><title>By: kalaivani</title><link>http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-60532</link> <dc:creator>kalaivani</dc:creator> <pubDate>Thu, 07 Jul 2011 09:38:38 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-60532</guid> <description>Hi frnd,
your query is gud, but i have one doubt while i&#039;m deleting.......
Suppose if i have two or more table and if that table contain more than 80000 records, and i find some duplicate records in my table &amp; try to delete them means the other table will be suffer or not? because i kept all id&#039;s as primary key &amp; set to other table into foreign key, while i&#039;m deleting a primary key, Will  foreign key show  error? or will  other table be suffered?</description> <content:encoded><![CDATA[<p>Hi frnd,<br
/> your query is gud, but i have one doubt while i&#8217;m deleting&#8230;&#8230;.<br
/> Suppose if i have two or more table and if that table contain more than 80000 records, and i find some duplicate records in my table &amp; try to delete them means the other table will be suffer or not? because i kept all id&#8217;s as primary key &amp; set to other table into foreign key, while i&#8217;m deleting a primary key, Will  foreign key show  error? or will  other table be suffered?</p> ]]></content:encoded> </item> <item><title>By: Ricky</title><link>http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-60527</link> <dc:creator>Ricky</dc:creator> <pubDate>Thu, 07 Jul 2011 04:05:15 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-60527</guid> <description>WOW your the MAN!!
I used exactly what you said and then i checked with
SELECT field_name,
COUNT(field_name) AS NumOccurrences
FROM cron_jobs
GROUP BY field_name
HAVING ( COUNT(field_name) &gt; 1 )
Worked like a charm!!</description> <content:encoded><![CDATA[<p>WOW your the MAN!!</p><p>I used exactly what you said and then i checked with</p><p>SELECT field_name,<br
/> COUNT(field_name) AS NumOccurrences<br
/> FROM cron_jobs<br
/> GROUP BY field_name<br
/> HAVING ( COUNT(field_name) &gt; 1 )</p><p>Worked like a charm!!</p> ]]></content:encoded> </item> <item><title>By: overseer</title><link>http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-59432</link> <dc:creator>overseer</dc:creator> <pubDate>Mon, 16 May 2011 09:56:54 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-59432</guid> <description>Totally awesome.</description> <content:encoded><![CDATA[<p>Totally awesome.</p> ]]></content:encoded> </item> <item><title>By: Jim</title><link>http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-59239</link> <dc:creator>Jim</dc:creator> <pubDate>Fri, 06 May 2011 01:39:49 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-59239</guid> <description>TRUNCATE TABLE bar WHERE duplicate IS true;</description> <content:encoded><![CDATA[<p>TRUNCATE TABLE bar WHERE duplicate IS true;</p> ]]></content:encoded> </item> <item><title>By: mkquake</title><link>http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-59143</link> <dc:creator>mkquake</dc:creator> <pubDate>Mon, 02 May 2011 18:59:10 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-59143</guid> <description>Sure, if you are working with 80286 !</description> <content:encoded><![CDATA[<p>Sure, if you are working with 80286 !</p> ]]></content:encoded> </item> <item><title>By: choudhury</title><link>http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-56363</link> <dc:creator>choudhury</dc:creator> <pubDate>Fri, 18 Mar 2011 03:00:42 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-56363</guid> <description>wow! This really worked for me...Thanks a lot Gerald...
---
DELETE FROM `MyTable`
WHERE `DuplCol` IN (
SELECT `DuplCol`
FROM (
SELECT `DuplCol` , count( * ) AS c
FROM `MyTable`
GROUP BY `DuplCol`
HAVING c &gt;1
) AS dctbl
)
AND `id` NOT IN (
SELECT `mi`
FROM (
SELECT `DuplCol` , min( `id` ) AS mi
FROM `MyTable`
GROUP BY `DuplCol`
) AS idtbl
);</description> <content:encoded><![CDATA[<p>wow! This really worked for me&#8230;Thanks a lot Gerald&#8230;<br
/> &#8212;<br
/> DELETE FROM `MyTable`<br
/> WHERE `DuplCol` IN (<br
/> SELECT `DuplCol`<br
/> FROM (</p><p>SELECT `DuplCol` , count( * ) AS c<br
/> FROM `MyTable`<br
/> GROUP BY `DuplCol`<br
/> HAVING c &gt;1<br
/> ) AS dctbl<br
/> )<br
/> AND `id` NOT IN (<br
/> SELECT `mi`<br
/> FROM (<br
/> SELECT `DuplCol` , min( `id` ) AS mi<br
/> FROM `MyTable`<br
/> GROUP BY `DuplCol`<br
/> ) AS idtbl<br
/> );</p> ]]></content:encoded> </item> <item><title>By: brij</title><link>http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-56340</link> <dc:creator>brij</dc:creator> <pubDate>Wed, 16 Mar 2011 13:12:43 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/#comment-56340</guid> <description>DELETE FROM vehicle_makes USING vehicle_makes,
vehicle_makes AS vtable WHERE (
NOT vehicle_makes.id = vtable.id
) AND (
vehicle_makes.name = vtable.name
)
=====================
id         name
=====================
2     Ottawa
3     AM General/Hummer
5     John Deere
4     WRV        6     WRV
17     Blue Bird
20     Chance
21     Crane Carrier
22     Crane Carrier
======================</description> <content:encoded><![CDATA[<p>DELETE FROM vehicle_makes USING vehicle_makes,<br
/> vehicle_makes AS vtable WHERE (<br
/> NOT vehicle_makes.id = vtable.id<br
/> ) AND (<br
/> vehicle_makes.name = vtable.name<br
/> )</p><p>=====================<br
/> id         name<br
/> =====================<br
/> 2     Ottawa<br
/> 3     AM General/Hummer<br
/> 5     John Deere<br
/> 4     WRV        6     WRV<br
/> 17     Blue Bird<br
/> 20     Chance<br
/> 21     Crane Carrier<br
/> 22     Crane Carrier<br
/> ======================</p> ]]></content:encoded> </item> </channel> </rss>
