Jump to content

AND OR statement


owner

Recommended Posts

Is there an AND OR type of statement in mySQL where if you select two fields you can sort them like: WHERE field=1 AND OR field2=1

 

That way if both fields matched it would be much more specific than just one field matching.

 

Thanks!

owner

Link to comment
Share on other sites

i'll try to help, just cuz i'm hanging out seeing if anyone will initially bite on my question.  i think the best help i can give you is to tell you that it is unclear what you are asking in your post.  you need to rephrase your question and providing an example query (the full query, not just the where clause) would prolly help too.  finally, although you question isn't affected by version so much... they are really anal about that here, so post your mysql server version too.  when in rome......

 

now "AND" and "OR" are both operators in sql.  you would use "AND" to match more than one statement and you would use "OR" to match just one statement.  so an attempt at helping you out, pay attention to the brackets... it's structured query language, it should make sense....

 

SELECT * FROM `database`.`table` WHERE (`field` = 1 AND `field2` = 1) OR (`field` = 2 AND `field2` = 2)

 

this would match rows where field and field2 both equal 1

it would also match rows where field and field2 both equal 2

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.