Page 1 of 1
Is it = or == for MySQL equality?
Posted: Wed Feb 04, 2009 1:28 pm
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?
Re: Is it = or == for MySQL equality?
Posted: Wed Feb 04, 2009 1:37 pm
by mickeyunderscore
Just a single = for MySQL.
Re: Is it = or == for MySQL equality?
Posted: Wed Feb 04, 2009 3:52 pm
by Skoalbasher
Code: Select all
$junk = "Some bs stuff here";
$query = "SELECT * FROM table_name WHERE column_name='$junk'";
Re: Is it = or == for MySQL equality?
Posted: Wed Feb 04, 2009 4:08 pm
by JAB Creations
I got it the first time, thanks.
Re: Is it = or == for MySQL equality?
Posted: Wed Feb 04, 2009 5:18 pm
by jayshields
And don't forget it's <> for inequality, not !=.
Re: Is it = or == for MySQL equality?
Posted: Wed Feb 04, 2009 5:22 pm
by JAB Creations
I always get < and > mixed up!

Good thing I know how to use a search engine!

I haven't used < or > for inequality in any instances I can think of offhand. Would != even work any way?
Re: Is it = or == for MySQL equality?
Posted: Wed Feb 04, 2009 5:40 pm
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.
Re: Is it = or == for MySQL equality?
Posted: Wed Feb 04, 2009 5:59 pm
by Benjamin
pytrin wrote:Personally I use != since it's similar to PHP.
Yeah I do as well.
Re: Is it = or == for MySQL equality?
Posted: Wed Feb 04, 2009 8:41 pm
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.
Re: Is it = or == for MySQL equality?
Posted: Wed Feb 04, 2009 9:58 pm
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.

Re: Is it = or == for MySQL equality?
Posted: Thu Feb 05, 2009 8:51 am
by jayshields
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.