Is it = or == for MySQL equality?

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
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Is it = or == for MySQL equality?

Post by JAB Creations »

I've put a lot of emphasis on preventing not just errors though warnings as well from any of the consoles in browsers and one of those errors I sometimes accidentally create (and of course end up fixing) is only using a single equal sign when I'm doing comparison. So I've been wondering as far as MySQL goes if I should be using one or two equal signs when I dictate WHERE to pull something from?
mickeyunderscore
Forum Contributor
Posts: 129
Joined: Sat Jan 31, 2009 9:00 am
Location: UK

Re: Is it = or == for MySQL equality?

Post by mickeyunderscore »

Just a single = for MySQL.
User avatar
Skoalbasher
Forum Contributor
Posts: 147
Joined: Thu Feb 07, 2008 8:09 pm

Re: Is it = or == for MySQL equality?

Post by Skoalbasher »

Code: Select all

 
$junk = "Some bs stuff here";
 
$query = "SELECT * FROM table_name WHERE column_name='$junk'";
 
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Is it = or == for MySQL equality?

Post by JAB Creations »

I got it the first time, thanks.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: Is it = or == for MySQL equality?

Post by jayshields »

And don't forget it's <> for inequality, not !=.
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Is it = or == for MySQL equality?

Post by JAB Creations »

I always get < and > mixed up! :| Good thing I know how to use a search engine! :mrgreen: I haven't used < or > for inequality in any instances I can think of offhand. Would != even work any way?
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Is it = or == for MySQL equality?

Post by Eran »

And don't forget it's <> for inequality, not !=
It's both for inequality. http://dev.mysql.com/doc/refman/5.0/en/ ... _not-equal
Personally I use != since it's similar to PHP.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Is it = or == for MySQL equality?

Post by Benjamin »

pytrin wrote:Personally I use != since it's similar to PHP.
Yeah I do as well.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Is it = or == for MySQL equality?

Post by John Cartwright »

jayshields wrote:And don't forget it's <> for inequality, not !=.
I've always reserved <> as a numerical operator, and != for textual comparison. Like others have said, they are interchangable.
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Is it = or == for MySQL equality?

Post by JAB Creations »

Thanks pytrin, that page doesn't come up when searching for "mysql operators" on Google. Geez they need to make their site like php.net. :|

Thanks for all the input, I'm happy I haven't been coding this incorrectly. :)
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: Is it = or == for MySQL equality?

Post by jayshields »

pytrin wrote:
Well I sort of think I knew that but thought <> was preferred.

@JAB, <> is nothing to do with < or >. < is less than, > is greater than, <> is inequality.
Post Reply