Jump to content


Photo

How to test for strings usng an IN clause


  • Please log in to reply
4 replies to this topic

#1 jaymc

jaymc
  • Members
  • PipPipPip
  • Advanced Member
  • 1,521 posts
  • LocationLiverpool

Posted 21 October 2006 - 07:09 PM

Take a look at the below code

SELECT * FROM artists WHERE ID IN (1,4,7,21,51) LIMIT 0,5

I'm sure you know what thats doing..

Well, ive just spend an hour trying to get this working..

SELECT * FROM artists WHERE username IN (ste,jeff,peter) LIMIT 0,3

I can only assume the IN() stuff works with numbers only?

If not, what am i doin wrong, if so... how can I replicate the function but querying for usernames rather than ID's

Thanks
I would love to change the world, but they won't give me the source code

SEO Agency

#2 fenway

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

Posted 22 October 2006 - 08:21 PM

You need to quote string literals.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 jaymc

jaymc
  • Members
  • PipPipPip
  • Advanced Member
  • 1,521 posts
  • LocationLiverpool

Posted 22 October 2006 - 09:53 PM

Can you give me an example?
I would love to change the world, but they won't give me the source code

SEO Agency

#4 fenway

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

Posted 22 October 2006 - 10:49 PM

SELECT * FROM artists WHERE username IN ('ste','jeff','peter') LIMIT 0,3

Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#5 jaymc

jaymc
  • Members
  • PipPipPip
  • Advanced Member
  • 1,521 posts
  • LocationLiverpool

Posted 23 October 2006 - 11:27 AM

Dam!! I didnt realise about the ' '

Thanks !
I would love to change the world, but they won't give me the source code

SEO Agency




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users