I have a table: tbl_offer (offer_name, location). For a particular offer I have more than one location in location column, separated by commas.
Example:
If offer is offer1 then I have Bangalore, Mumbai, Chennai in the location column.
Now want to write a query which will fetch each location separately (which are separated by commas for a particular offer). I want choose the offer1 it should fetch Bangalore Mumbai and Chennai in separate records.
As @Cylindric told you, if you can change database design!
Create two tables, one for offers and one for location.
So (for example) you have
(1, 'offer1')in OFFERS and(1, 'Bangalore'), (1, 'Mumbai') and (1, 'Chennai')in LOCATIONS.Your query will be easier:
To be honest, you should have three tables to avoid locations repetitions:
You have
(1, 'offer1')in OFFERS,(1, 'Bangalore'), (2, 'Mumbai') and (3, 'Chennai')in LOCATIONS and(1, 1), (1, 2) and (1, 3)in OFFERS_LOC.Your query will be