Jump to content


Photo

mysql Multiple statements


  • Please log in to reply
3 replies to this topic

#1 JamesRyzon

JamesRyzon
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 07 July 2006 - 12:35 AM

Having some trouble with mysql statements wanting to run multiple types at once this is an example

SELECT * FROM cars WHERE Year='$year' AND Model='Ford' OR 'GM'

Just as an exmaple, the query only returns cars from 1990 and Ford type, skipping GM.

Any helpful hints on this?

#2 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 07 July 2006 - 12:40 AM

...AND Model='Ford' OR Model='GM'

Which could also be expressed:

...AND Model IN ('Ford', 'GM')
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#3 JamesRyzon

JamesRyzon
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 07 July 2006 - 01:02 AM

Thank you for your quick reply!

That was exactily what i was looking for but I didnt know about "IN" in sql, thanks again!

#4 fenway

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

Posted 07 July 2006 - 06:31 AM

If you didn't use IN(), you should probably use parens to make it explicit.
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