Mysql批量删除使用“不在”

时间:2010-04-04 10:45:23

标签: mysql bulk sql-delete

任何人都可以帮我解决这个mysql查询:

delete from generic__campaings_included where dealer_id not in ('2,3,4') and campaing_id = '1'

当我执行此查询时,我没有得到正常结果。除了2(dealer_id)以外的所有行都被删除了。

如何在“and”运算符中使用“not in”?

1 个答案:

答案 0 :(得分:3)

如果没有单引号,这不是吗?

delete from generic__campaings_included where dealer_id not in (2,3,4) and campaing_id = 1

或者如果列是字符串

delete from generic__campaings_included where dealer_id not in ('2','3','4') and campaing_id = '1'

您删除了dealer_id <> '2,3,4'的行(即字符串文字,而不是2,3或4之一)