Jump to content


Photo

**SOLVED** MySQL SELECT help


  • Please log in to reply
2 replies to this topic

#1 phporcaffeine

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

Posted 29 April 2006 - 10:39 PM

Okay,

Here is the basis of my query

SELECT col_1, col_2, col_4, col_8 FROM tbl_name WHERE status='value_1' OR status='value_2' AND company='value';

Of course it bombs and I know it's because of " AND company='value' "

I'm guessing that I can't do status="value_1' OR status='value_2' - plus - AND company=' '

It doesn't make 'boolean' sense, I know.

I'm hoping there is a way around this?
Thanks,

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

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,023 posts

Posted 29 April 2006 - 11:35 PM

Queries using AND and OR can be ambiguous so use (...) to make sure the logic is clear

Do you mean

...WHERE ((status='value_1') OR (status='value_2')) AND company='value'

or

...WHERE (status='value_1') OR ( status='value_2' AND company='value')

if it's the former, a clearer alternative is

...WHERE status IN ('value_1' , 'value_2') AND company='value'

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 phporcaffeine

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

Posted 30 April 2006 - 03:12 AM

[!--quoteo(post=369982:date=Apr 29 2006, 07:35 PM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Apr 29 2006, 07:35 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Queries using AND and OR can be ambiguous so use (...) to make sure the logic is clear

Do you mean

...WHERE ((status='value_1') OR (status='value_2')) AND company='value'

or

...WHERE (status='value_1') OR ( status='value_2' AND company='value')

if it's the former, a clearer alternative is

...WHERE status IN ('value_1' , 'value_2') AND company='value'
[/quote]

Thanks! It Worked
Thanks,

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users