H
H
HeBonpoc2014-09-07 20:16:38
MySQL
HeBonpoc, 2014-09-07 20:16:38

(mysql) How to remove rows that are not unique for a certain field from a table?

Table:

8;privet
9;privet
10;hi
11;hello

Line 8 or 9 will be deleted - it doesn't matter. Can this be done in SQL?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
HeBonpoc, 2014-09-07
@HeBonpoc

Delete from the product_image table by the img field:

DELETE t1 FROM product_image t1
JOIN (SELECT MIN(id) AS minid, img FROM product_image GROUP BY img) t2 
ON t1.id <> t2.minid AND t1.img = t2.img

V
vdem, 2014-09-07
@vdem

Banned on google? The first link:
www.cyberforum.ru/mysql/thread224262.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question