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 Link to comment https://forums.phpfreaks.com/topic/237521-please-correct-my-mysql-query/ 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 Link to comment https://forums.phpfreaks.com/topic/237521-please-correct-my-mysql-query/#findComment-1220546 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. Link to comment https://forums.phpfreaks.com/topic/237521-please-correct-my-mysql-query/#findComment-1220652 Share on other sites More sharing options...
suresh_kamrushi Posted May 26, 2011 Share Posted May 26, 2011 IN() will not work for CSV!!!!!!!!!!!! Link to comment https://forums.phpfreaks.com/topic/237521-please-correct-my-mysql-query/#findComment-1220691 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. Link to comment https://forums.phpfreaks.com/topic/237521-please-correct-my-mysql-query/#findComment-1220860 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.