i have a mysql table category with a field events as varchar which its values is like this : 11,29,32.and this values referer to event table ID. ( so i can say : i have a several event ID from event table in category table)
So i want to select events from category like that :
SELECT *
FROM
event e, category c
where e.event_id in (c.events)
But that not give the correct result instead when i put the values manually like :
SELECT *
FROM
event e, category c
where e.event_id in (11,29,32)
I hope that’s clear,
Any help please
Part of your problem is the way that you have set up your tables. Typically you will have an
events,categoryand then a join table between the two. You should not store data in a comma separated list to query against.If you cannot alter your table structure, then you can use the MySQL function
FIND_IN_SET():See SQL Fiddle with Demo
If you can alter your tables, then the structure should be:
Then when you query the data you would use: