Answer the question
In order to leave comments, you need to log in
SQL query to remove duplicates from a table by 3 fields?
Tell me how to remove duplicate values for the fields product_id, category_id, modification_id
id|product_id|category_id|modification_id|
--|----------|-----------|---------------|
1| 333| 133| 17344|
2| 333| 133| 17344|
3| 333| 133| 17344|
4| 333| 133| 17344|
5| 333| 133| 17344|
6| 333| 133| 17344|
7| 333| 133| 17344|
8| 333| 133| 17344|
9| 333| 133| 17344|
10| 333| 133| 17344|
11| 333| 133| 2069|
12| 333| 133| 2069|
13| 338| 387| 18361|
14| 338| 387| 18361|
15| 333| 133| 17344|
16| 333| 133| 17344|
17| 333| 133| 17344|
18| 333| 133| 17344|
19| 333| 133| 17344|
20| 333| 133| 17344|
id|product_id|category_id|modification_id|
--|----------|-----------|---------------|
1| 333| 133| 17344|
11| 333| 133| 2069|
13| 338| 387| 18361|
15| 333| 133| 17344|
Answer the question
In order to leave comments, you need to log in
More or less like this:
DELETE t1 FROM tbl_name t1
INNER JOIN tbl_name t2
WHERE
t1.id < t2.id AND
t1.product_id = t2.product_id AND
t1.category_id = t2.category_id AND
t1.modification_id = t2.modification_id;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question