109

I need to do this

DELETE FROM konta WHERE taken != ''

But != doesn't exist in mysql. Anyone know how to do this?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Posttwo
  • 1,274
  • 2
  • 9
  • 13

3 Answers3

167
DELETE FROM konta WHERE taken <> '';
RolandoMySQLDBA
  • 43,883
  • 16
  • 91
  • 132
46

The != operator most certainly does exist! It is an alias for the standard <> operator.

Perhaps your fields are not actually empty strings, but instead NULL?

To compare to NULL you can use IS NULL or IS NOT NULL or the null safe equals operator <=>.

Mark Byers
  • 811,555
  • 193
  • 1,581
  • 1,452
  • Eh, I can see where the `NULL` is going (+1), but it seems odd to want to delete *not empty* or NULL .. –  Jul 10 '12 at 20:57
13

You may be using old version of Mysql but surely you can use

 DELETE FROM konta WHERE taken <> ''

But there are many other options available. You can try the following ones

DELETE * from konta WHERE strcmp(taken, '') <> 0;

DELETE * from konta where NOT (taken = '');
minhas23
  • 9,291
  • 3
  • 58
  • 40