If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Is there a purely SQL way of getting rid of duplicates in a table?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-09-12, 15:44
HunterDX77M HunterDX77M is offline
Registered User
 
Join Date: Jan 2012
Posts: 11
Question Is there a purely SQL way of getting rid of duplicates in a table?

I'm dealing with a table that has been having issues with duplicate rows. I want to remove every extra row in the table. (The duplication problems occur when someone else's script runs on the table, and we've yet to pin point the location of the bug.)

I can think of at least one way to do this with a combination of PHP and MySQL, but I was wondering if MySQL alone had a mechanism that could do this already.
Reply With Quote
  #2 (permalink)  
Old 02-09-12, 16:00
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
yes, you are fortunate, mysql has a really neat mechanism...
Quote:
Originally Posted by da manual
IGNORE is a MySQL extension to standard SQL. It controls how ALTER TABLE works if there are duplicates on unique keys in the new table or if warnings occur when strict mode is enabled. If IGNORE is not specified, the copy is aborted and rolled back if duplicate-key errors occur. If IGNORE is specified, only the first row is used of rows with duplicates on a unique key. The other conflicting rows are deleted. Incorrect values are truncated to the closest matching acceptable value.
-- MySQL :: MySQL 5.0 Reference Manual :: 12.1.4 ALTER TABLE Syntax
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 02-09-12, 16:16
HunterDX77M HunterDX77M is offline
Registered User
 
Join Date: Jan 2012
Posts: 11
Quote:
Originally Posted by r937 View Post
yes, you are fortunate, mysql has a really neat mechanism...
I see. Thanks.
Reply With Quote
Reply

Tags
duplicate, remove, rows

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On