Jump to content


Photo

MySQL SELECT Query Question


  • Please log in to reply
4 replies to this topic

#1 phporcaffeine

phporcaffeine
  • Members
  • PipPipPip
  • Advanced Member
  • 361 posts
  • LocationOhio, USA

Posted 27 April 2006 - 02:40 PM

What's the 'proper' syntax for multiple WHERE conditions?

1.) SELECT * FROM table WHERE col_1 = 'val_1' AND col_2 = 'val_2' ?

2.) SELECT * FROM table WHERE col=1 = 'val_1', col_2='val_2' ?


Thanks,

Ryan Huff
President & Founder, MyCodeTree
support@mycodetree.com | http://mycodetree.com

#2 onepixel

onepixel
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 27 April 2006 - 03:01 PM

[!--quoteo(post=369245:date=Apr 27 2006, 09:40 AM:name=phpORcaffine)--][div class=\'quotetop\']QUOTE(phpORcaffine @ Apr 27 2006, 09:40 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
What's the 'proper' syntax for multiple WHERE conditions?

1.) SELECT * FROM table WHERE col_1 = 'val_1' AND col_2 = 'val_2' ?

2.) SELECT * FROM table WHERE col=1 = 'val_1', col_2='val_2' ?
[/quote]


The first expression is the right one:
SELECT * FROM table WHERE col_1 = 'val_1' AND col_2 = 'val_2' ;
<a href="http://www.saheltech.com">PHP Programming - WordPress Blog Customization</a>

#3 bbaker

bbaker
  • Members
  • PipPipPip
  • Advanced Member
  • 127 posts
  • LocationNY

Posted 27 April 2006 - 03:02 PM

#1 (if the query must satisfy BOTH WHERE conditions, replace AND with OR if it can meet one or the other.)


guess you already got it ;]

#4 phporcaffeine

phporcaffeine
  • Members
  • PipPipPip
  • Advanced Member
  • 361 posts
  • LocationOhio, USA

Posted 27 April 2006 - 03:08 PM

Yeah, I got it ....

I was going nuts I couldn't get why my query was bombing? Then I noticed I had 'AND' in the query as 'ADN'


BIG DIFFERENCE when you can spell, LMAO
Thanks,

Ryan Huff
President & Founder, MyCodeTree
support@mycodetree.com | http://mycodetree.com

#5 emehrkay

emehrkay
  • Staff Alumni
  • Advanced Member
  • 1,214 posts

Posted 27 April 2006 - 03:18 PM

[!--quoteo(post=369254:date=Apr 27 2006, 11:08 AM:name=phpORcaffine)--][div class=\'quotetop\']QUOTE(phpORcaffine @ Apr 27 2006, 11:08 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Yeah, I got it ....

I was going nuts I couldn't get why my query was bombing? Then I noticed I had 'AND' in the query as 'ADN'
BIG DIFFERENCE when you can spell, LMAO
[/quote]
maybe its the lack of caffine




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users