-1

Anybody can help me with this mysql query:

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

When I execute this query I didn't get normal result. Except 2 (dealer_id) all rows deleted.

How can I use "not in" with "and" operator?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Nadir
  • 1
  • 3
    It really does help to run a `select` first, to check if you got the 'where' clause right (or even if you got it at all), if you are unsure. Actually, it pays to do it every time. – shylent Apr 04 '10 at 11:01
  • @shylent +1 - It also pays to use transaction control so you can `ROLLBACK` if you mess up. – amphetamachine Apr 04 '10 at 12:39

1 Answers1

3

Should it not be this without single quotes?

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

or this if the columns are string

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

You deleted rows where dealer_id <> '2,3,4' (that is, a string literal rather than one of 2, 3, or 4)

gbn
  • 422,506
  • 82
  • 585
  • 676