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
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]
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.