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 > IN Clause not seeing val in comma-delim list?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-13-05, 11:44
weblingual weblingual is offline
Registered User
 
Join Date: Dec 2004
Posts: 2
Arrow IN Clause not seeing val in comma-delim list?

Hello,

The first query below is not returning my row? It should... I am at a loss. The stored value in a.genrePIDs is "131,79". If the value is 131, 2nd query below, then my row is returned. But no row is returned if I am looking for 79. If I add the string '79' between the (,'79')'s, 3rd query below, then my row is returned.

Any ideas?


SELECT a.trackID
FROM tracks a
WHERE 79 IN (a.genrePIDs) <- ROW IS NOT RETURNED


SELECT a.trackID
FROM tracks a
WHERE 131 IN (a.genrePIDs) <- ROW IS RETURNED


SELECT a.trackID
FROM tracks a
WHERE 79 IN (a.genrePIDs,'79') <- ROW IS RETURNED


Using: MySQL 4.1

Thanks
Reply With Quote
  #2 (permalink)  
Old 01-14-05, 08:00
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
this is a great example of why they tell you never to store a comma-separated list of values in a single column

it breaks first normal form and makes joining on the column next to impossible

can you redesign the table properly?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 01-17-05, 11:06
the_spas the_spas is offline
Registered User
 
Join Date: Jan 2005
Posts: 10
jap looks like a refactoring is on schedule

you can do someting like this

make a assignment table
track_id, genre_id both smalest type you expect
mediumint 8 unsigned should do it (if no negative values are needed)

and later do a subselect
somthing like
WHERE X IN (SELECT genre_id FROM assignment_tabe b WHERE b.track_id = a.track_id )

i like the 4.1 version :0)
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