MySQL WHERE: how to write "!=" or "not equals"?

MysqlSql Delete

Mysql Problem Overview


I need to do this

DELETE FROM konta WHERE taken != ''

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

Mysql Solutions


Solution 1 - Mysql

DELETE FROM konta WHERE taken <> '';

Solution 2 - Mysql

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 <=>.

Solution 3 - Mysql

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 = '');

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPosttwoView Question on Stackoverflow
Solution 1 - MysqlRolandoMySQLDBAView Answer on Stackoverflow
Solution 2 - MysqlMark ByersView Answer on Stackoverflow
Solution 3 - Mysqlminhas23View Answer on Stackoverflow