If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Using varchar column as argument to IN ()

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-03-08, 09:57
Oddish Oddish is offline
Registered User
 
Join Date: Mar 2003
Posts: 43
Using varchar column as argument to IN ()

I've got a varchar column which contains values like "123, 234, 345" and I'd like to use this value as the argument to IN (). If I specify the values like this:

WHERE foo IN (1,2,3)

... everthing works fine, but when I try to use a column:

WHERE foo IN (varchar_column_containing_comma-delimited_numbers)

... it doesn't work as expected. What am I doing wrong?
Reply With Quote
  #2 (permalink)  
Old 09-03-08, 10:11
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
to answer your question: use FIND_IN_SET function

to give you good advice: never store a list of ids in a single column
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 09-03-08, 10:22
Oddish Oddish is offline
Registered User
 
Join Date: Mar 2003
Posts: 43
Quote:
Originally Posted by r937
to answer your question: use FIND_IN_SET function
It works, but my god it's slow...

Quote:
Originally Posted by r937
to give you good advice: never store a list of ids in a single column
I'm well aware, but I need a quick and dirty solution at the moment.

Thanks!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On