Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I need to do this

DELETE FROM konta WHERE taken != ''

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

like image 463
Posttwo Avatar asked Jul 10 '12 20:07

Posttwo


People also ask

Can we use != In MySQL?

In MySQL, you can use the <> or != operators to test for inequality in a query. For example, we could test for inequality using the <> operator, as follows: SELECT * FROM contacts WHERE last_name <> 'Johnson';

Can we use != In SQL query?

We can use both SQL Not Equal operators <> and != to do inequality test between two expressions. Both operators give the same output. The only difference is that '<>' is in line with the ISO standard while '!=

Is != and <> the same in SQL?

If != and <> both are the same, which one should be used in SQL queries? Here is the answer – You can use either != or <> both in your queries as both technically same but I prefer to use <> as that is SQL-92 standard.

Is not and != In SQL?

NOT negates the following condition so it can be used with various operators. != is the non-standard alternative for the <> operator which means "not equal". e.g. In some situations it might be easier to understand to negate a complete expression rather then rewriting it to mean the opposite.


3 Answers

DELETE FROM konta WHERE taken <> '';
like image 111
RolandoMySQLDBA Avatar answered Oct 22 '22 06:10

RolandoMySQLDBA


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

like image 44
Mark Byers Avatar answered Oct 22 '22 05:10

Mark Byers


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 = '');
like image 13
minhas23 Avatar answered Oct 22 '22 06:10

minhas23