Page 1 of 1

mySQL NOT/ not equal to?

Posted: Wed Jul 29, 2009 6:50 am
by Sindarin
mySQL says this is wrong:

SELECT * FROM homes WHERE !`home_geo`=''

So how can I ask for cells when a value is NOT equal to a value?
like in php I can do

if (!$var==2)
{
}

Re: mySQL NOT/ not equal to?

Posted: Wed Jul 29, 2009 7:08 am
by Eran
it would be != (and you should do the same in PHP, which is more readable in my opinion)
http://dev.mysql.com/doc/refman/5.0/en/ ... ators.html

Re: mySQL NOT/ not equal to?

Posted: Wed Jul 29, 2009 7:20 am
by VladSun
<> is the same, but it conforms to the SQL standard.
MySQL 5.1: supports both != and <>
PostgreSQL 8.3: supports both != and <>
SQLite: supports both != and <>
Oracle 10g: supports both != and <>
Microsoft SQL Server 2000/2005/2008: supports both != and <>
IBM DB2 UDB 9.5: supports only <>
IBM Informix Dynamic Server 10: supports both != and <>
InterBase/Firebird: supports both != and <>
Apache Derby: supports only <>

Re: mySQL NOT/ not equal to?

Posted: Wed Jul 29, 2009 7:31 am
by VladSun
pytrin++ about the PHP part:

Code: Select all

if (!$var==2)
should be

Code: Select all

if ($var!==2)
1. true if $var IS integer (or numeric data type) and its value is not 2
2. true if $var IS NOT integer

or

Code: Select all

if ($var!=2)
true if $var value is not 2 (doesn't matter whether it's string or numeric data type)

You see, when I encounter

Code: Select all

if (!$var==2)
I start to wonder which operand has higher precedence - the ! or the ==.

Code: Select all

if ((!$var)==2)
is very different from

Code: Select all

if (!($var==2))
, right ?

And in the

Code: Select all

if ($var!=2)
form it's crystal clear.

Re: mySQL NOT/ not equal to?

Posted: Thu Jul 30, 2009 6:46 am
by Sindarin
Thanks people it works.