I'm just wondering what kind of mysql command i could execute in php that would select all items from a certain table where columna is not equal to x and columnb is not equal to x
Something like: select something from table where columna does not equal x and columnb does not equal x
Any ideas?
Or can also insert the statement inside bracket.
SELECT * FROM tablename WHERE NOT (columnA = 'x')
You can use like
NOT columnA = 'x'
Or
columnA != 'x'
Or
columnA <> 'x'
And like Jeffly Bake's query, for including null values, you don't have to write like
(NOT columnA = 'x' OR columnA IS NULL)
You can make it simple by
Not columnA <=> 'x'
<=> is the Null Safe equal to Operator, which includes results from even null values.
You can use also
select * from tablename where column1 ='a' and column2!='b';
$sqlquery = "SELECT field1, field2 FROM table WHERE columnA <> 'x' AND columbB <> 'y'";
I'd suggest using the diamond operator (<>) in favor of != as the first one is valid SQL and the second one is a MySQL addition.
select * from table where fiels1 NOT LIKE 'x' AND field2 NOT LIKE 'y'
//this work in case insensitive manner
Source: Stackoverflow.com