Jump to content


Photo

"OR" im trying to find a field which has a or b or c in it


  • Please log in to reply
4 replies to this topic

#1 mojito

mojito
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts

Posted 21 June 2006 - 07:55 PM

Im trying to look in a single field for theoccurance of one of three strings..looking at an operator page on mysql.com i see that to get or you just use a space so
....WHERE virtualName='stringone stringtwo stringthree' 

I would like to get a hit if the field contains either "stringone" or "stringtwo" or "stringthree"

thanks for any help.

mojito

#2 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 21 June 2006 - 08:03 PM

The easiest way to do it is:
WHERE virtualName='stringone' OR virtualName='stringtwo' OR virtualName='stringthree'


#3 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 23 June 2006 - 07:32 AM

Actually, IMHO, an IN clause is "easier":

WHERE virtualName IN ( 'stringone', 'stringtwo', 'stringthree' )

Not to mention that it makes the conversion from an array trivial... plus I'm sure the optimizer has less work to do.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#4 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 23 June 2006 - 01:37 PM

O cool...didn't know you could do that.


What do you know...you learn something new every day!

#5 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 24 June 2006 - 07:52 AM

[!--quoteo(post=387154:date=Jun 23 2006, 09:37 AM:name=cmgmyr)--][div class=\'quotetop\']QUOTE(cmgmyr @ Jun 23 2006, 09:37 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
O cool...didn't know you could do that.
What do you know...you learn something new every day!
[/quote]
I wish that was actually true.... [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /]
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users