tags:

views:

131

answers:

7

I want to select all the fields where a certain column is not a value I specify.

I tried this but it didn't work.

SELECT * 
FROM table 
WHERE columnname != value

My mistake.

It was another error so I thought it was wrong with != operator cause it was the first time I use it. Sorry guys!

A: 
WHERE NOT columnname = value
Dave
+10  A: 
SELECT * 
FROM table 
WHERE columnname <> value
Mitch Wheat
according to the MySQL spec this is the same as !=
philfreo
@philfreo: That's the point of *alternatives*.
OMG Ponies
Thanks to the downvoter.
Mitch Wheat
Yes but by giving an answer of `<>` it appears that his original query of `!=` was wrong, when in fact the issue is something else.
philfreo
+3  A: 

In SQL, I believe inequality is

<>

though many implementations also allow

!=
Ken
+2  A: 

Either <> or !=

From: MySQL Manual (version 5.0)

<>, !=

Not equal:

mysql> SELECT '.01' <> '0.01'; -> 1 mysql> SELECT .01 <> '0.01'; -> 0 mysql> SELECT 'zapp' <> 'zappp'; -> 1

David Thomas
+5  A: 

For MySQL: != or <> are correct.

http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html

You should consider NULL columns also. You can do WHERE columnname IS NOT NULL also.

philfreo
A: 

NOT IN is one flavor and here's a tsql negate example

LarsOn
Not applicable, based on the example
OMG Ponies
+1  A: 

You need to post the query you are using, because != works fine for me in MySQL 4.1

As others mentioned, <> is equivalent. The != is ANSI standard (99 I believe).

OMG Ponies