Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Problem with IN()

Problem with IN()

Problem with IN()

I've stored lists of numbers in columns, that looks like this:
I've chosen varchar(255) to store these values. Let's call this column "numbers".

Now, I want to find out which rows holds a certain number. So, these two query should both return 1, right?

Query 1: SELECT 6 IN(1,2,6,7);
Query 2: SELECT 6 IN(numbers) FROM my_table;

The problem is that MySQL seems to interpret the second query like this:
SELECT 6 IN('1,2,6,7') FROM my_table;
...since "1,2,6,7" is stored as a string, so it doesn't work.

How can I make MySQL understand that I want it to be interpreted like QUERY 1?

RE: Problem with IN()


SELECT * FROM your_table WHERE the_column LIKE "%the_number%"

I hope it works...

RE: Problem with IN()

I forgot to mention that the numbers will not always be one-digit.
But that's okay, 'cause I fixed it through the amazing powers of regular expressions, yaay!

SELECT * FROM my_table WHERE  numbers REGEXP "(^|,)6(,|$)";

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close