Is it = or == for MySQL equality?
Moderator: General Moderators
- JAB Creations
- DevNet Resident
- Posts: 2341
- Joined: Thu Jan 13, 2005 6:44 pm
- Location: Sarasota Florida
- Contact:
Is it = or == for MySQL equality?
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?
Just a single = for MySQL.
- Skoalbasher
- Forum Contributor
- Posts: 147
- Joined: Thu Feb 07, 2008 8:09 pm
Re: Is it = or == for MySQL equality?
Code: Select all
$junk = "Some bs stuff here";
$query = "SELECT * FROM table_name WHERE column_name='$junk'";
- 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?
I got it the first time, thanks.
- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
Re: Is it = or == for MySQL equality?
And don't forget it's <> for inequality, not !=.
- 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?
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?
It's both for inequality. http://dev.mysql.com/doc/refman/5.0/en/ ... _not-equalAnd don't forget it's <> for inequality, not !=
Personally I use != since it's similar to PHP.
Re: Is it = or == for MySQL equality?
Yeah I do as well.pytrin wrote:Personally I use != since it's similar to PHP.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Is it = or == for MySQL equality?
I've always reserved <> as a numerical operator, and != for textual comparison. Like others have said, they are interchangable.jayshields wrote:And don't forget it's <> for inequality, not !=.
- 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?
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.
Thanks for all the input, I'm happy I haven't been coding this incorrectly.
- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
Re: Is it = or == for MySQL equality?
Well I sort of think I knew that but thought <> was preferred.pytrin wrote:It's both for inequality. http://dev.mysql.com/doc/refman/5.0/en/ ... _not-equal
@JAB, <> is nothing to do with < or >. < is less than, > is greater than, <> is inequality.