Jump to content

**SOLVED** MySQL SELECT help


phporcaffeine

Recommended Posts

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?
Link to comment
https://forums.phpfreaks.com/topic/8729-solved-mysql-select-help/
Share on other sites

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

Do you mean

[code]...WHERE ((status='value_1') OR (status='value_2')) AND company='value'[/code]

or

[code]...WHERE (status='value_1') OR ( status='value_2' AND company='value')
[/code]

if it's the former, a clearer alternative is

[code]...WHERE status IN ('value_1' , 'value_2') AND company='value'[/code]
[!--quoteo(post=369982:date=Apr 29 2006, 07:35 PM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Apr 29 2006, 07:35 PM) [snapback]369982[/snapback][/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

[code]...WHERE ((status='value_1') OR (status='value_2')) AND company='value'[/code]

or

[code]...WHERE (status='value_1') OR ( status='value_2' AND company='value')
[/code]

if it's the former, a clearer alternative is

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

Thanks! It Worked

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.