I believe you could do:

SELECT *
FROM Table
WHERE FIND_IN_SET(number, comma_delimited_field)

but this will be /very/ slow. This query is forced to
examine each and every row to determine whether or not your
number is in the field.

The better solution is to break up that field, which is
generally easier than you'd think. If your table looks like
this:

foo    bar
100    1,2,3
101    2,3
102    4,5,6

you can easily convert it to one that looks like:

foo    bar
100    1
100    2
100    3
101    2
101    3
102    4
102    5
102    6

This moves you from varchars to ints, variable-length rows
to fixed, and you'll now be able to index bar properly.
You'll see a dramatic performance improvement.

____________________________________________________________
Eamon Daly



----- Original Message ----- 
From: "Eric Scuccimarra" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, June 24, 2004 10:11 AM
Subject: Query Problem with Lists


> I have a table where one field is a long list of numbers in
comma-delimited
> format.
>
> I need to do a query like:
>
> SELECT *
> FROM Table
> WHERE [number] IN list
>
> If I cut and paste the actual list in it works fine but when I use the
> column-name containing the list it returns nothing. I've been searching
the
> MySQL docs for hours and haven't turned up anything. Apparently I can use
> set functions but the lists seem to be too big to store as sets.
>
> Any help is appreciated.
>
> Eric


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to