|
Posted by Jamie Alessio on 03/15/05 02:44
> I have table with products. In column categories are listed numbers of
> categories a product belongs, like:
> 1. 21,
> 2. 35, 8, 72, 1, 4,
> 3. 23, 11, 48,
> 4. 65,
> 5. 11,
> 6. 23,
> 7. ...
> (somebody else created the table this way and I have to keep it for the
> moment)
> Now, I have to list all products that belongs to category with cat.
> number, e.g. 11.
>
Afan,
If you're using MySQL check out the FIND_IN_SET() function. Since your
category data is comma separated you should be able to do something like:
SELECT product
FROM products
WHERE
FIND_IN_SET('11', REPLACE (categories, ' ', '')) > 0
You need the extra REPLACE() call there to remove the spaces or else
FIND_IN_SET() for your numbers won't work properly.
Details on the function at
http://dev.mysql.com/doc/mysql/en/string-functions.html
- Jamie
[Back to original message]
|