Jump to content

Archived

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

phporcaffeine

**SOLVED** MySQL SELECT help

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?

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
[!--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

Share this post


Link to post
Share on other sites

×

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.