piyush23424 Posted May 26, 2011 Share Posted May 26, 2011 I have comma separated values in table column name cityid(datatype is varchar). Now i want to fetch the records from that table based upon those ids with pattern matching technique eg. cityid has 3,4,5,10,5,60,2 values. Here each id is reference to different cities. i have tried following query but it didn't worked for me $sql = "Select * from table where cityid like %id%" i think we can do it with pattern matching. please help Thanks Quote Link to comment Share on other sites More sharing options...
suresh_kamrushi Posted May 26, 2011 Share Posted May 26, 2011 Hi, you can do it with the help of regular expression in Mysql Select * from table where cityid REGEXP '^9,|,9$|,9,' OR cityid =9 Quote Link to comment Share on other sites More sharing options...
Maq Posted May 26, 2011 Share Posted May 26, 2011 CSV fields are a horrible idea, don't do that. You need to use the IN() function. Quote Link to comment Share on other sites More sharing options...
suresh_kamrushi Posted May 26, 2011 Share Posted May 26, 2011 IN() will not work for CSV!!!!!!!!!!!! Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted May 26, 2011 Share Posted May 26, 2011 IN() will not work for CSV!!!!!!!!!!!! I think he means convert the csv to single rows, then do an in on it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.