I have a sql database named "data" and a table "disk", where there are 5 columns
CREATE TABLE disk
(
id
int(11) NOT NULL,
title
text COLLATE utf8_unicode_ci NOT NULL,
link
text COLLATE utf8_unicode_ci NOT NULL,
mag
text COLLATE utf8_unicode_ci NOT NULL,
size
varchar(10) COLLATE utf8_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
the "mag" column has a some of the duplicates.
and I want to delete the complete row where mag column is same.
note:- let say mag column has 1,2,3,4,4,5.... I want to delete a single 4 from it which is duplicate. means I don't want to completely delete both the 4. one "4" must be kept.
tell the SQL query which can do that.... before marking this question as a duplicate, I must tell you that I have already seen the similar question but none of them worked. for more info just comment.
No need to create any temporary tables
I hope this will work for you
Please also check the following link your for more suggestions
MySQL delete duplicate records but keep latest
You can do the following..
Creating new table and keeping random row :
first copy table
disk
(unique data) to temp tabledisk2
.drop table
disk
.rename temp table
disk2
todisk
.NOTE : Here we using
group by
with*
because OP does not care which row to keep.Creating new table and keeping row with min or max id : Another way to do this while keeping row with
min
ormax
idUPDATE: Another way to do this
Deleting duplicates from existing table
Try this:
For Demo Follow the below link:
try this below to delete duplicate with same d column and keep one row with lowest id value: :