mySQL NOT/ not equal to?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Sindarin
Forum Regular
Posts: 521
Joined: Tue Sep 25, 2007 8:36 am
Location: Greece

mySQL NOT/ not equal to?

Post 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)
{
}
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: mySQL NOT/ not equal to?

Post 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
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: mySQL NOT/ not equal to?

Post 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 <>
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: mySQL NOT/ not equal to?

Post 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.
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
Sindarin
Forum Regular
Posts: 521
Joined: Tue Sep 25, 2007 8:36 am
Location: Greece

Re: mySQL NOT/ not equal to?

Post by Sindarin »

Thanks people it works.
Post Reply