在MySQL中,是否可以删除字段等于具有前缀?
的另一行的位置例如(伪代码):
DELETE from `table` WHERE `field` = CONCAT("duplicate-of-", field)
假设我有这些行,我想删除所有具有该前缀的相应重复项
+ Field +
------------------------
| name |
| duplicate-of-name |
| name2 |
| duplicate-of-name2 |
答案 0 :(得分:0)
您可以使用exists
运算符解决此问题:
DELETE
FROM `table` t1
WHERE EXISTS (SELECT *
FROM `table` t2
WHERE t2.`field` = CONCAT("duplicate-of-", t1.field))
答案 1 :(得分:0)
您可以使用join
:
DELETE tdup
FROM table tdup JOIN
table t
ON tdup.field = CONCAT('duplicate-of-', t.field);