mapleleaf Posted December 2, 2009 Share Posted December 2, 2009 I have a field in the database with ids in it. Eg 3 fields below: 1,43,89,4,923 55,14, 402,77 44,8,23 How do I search for only the id 4 and not return 44, 43, 14, 402 etc? In this case i want only the first row returned. I am sure MYSQL will have someting for this. Thanks Link to comment https://forums.phpfreaks.com/topic/183693-get-a-unique-id-from-a-comma-separated-string/ Share on other sites More sharing options...
JonnoTheDev Posted December 2, 2009 Share Posted December 2, 2009 http://dev.mysql.com/doc/refman/5.1/en/regexp.html Link to comment https://forums.phpfreaks.com/topic/183693-get-a-unique-id-from-a-comma-separated-string/#findComment-969621 Share on other sites More sharing options...
fenway Posted December 2, 2009 Share Posted December 2, 2009 FIND_IN_SET() will work too under limited circumstances. Link to comment https://forums.phpfreaks.com/topic/183693-get-a-unique-id-from-a-comma-separated-string/#findComment-969802 Share on other sites More sharing options...
mapleleaf Posted December 4, 2009 Author Share Posted December 4, 2009 I am not sure whether regex will work for this as I need the query to be able to find any id 2 or 22 or 32 etc. For FIND IN SET I am struggling to write a query that might work. Seems like it needs subqueries which I am not familiar with. i am trying something like this: SELECT IN SET( '6', '( SELECT second_theme FROM articles WHERE second_theme LIKE ' %6 % ')' ) FROM articles Any ideas much appreciated Link to comment https://forums.phpfreaks.com/topic/183693-get-a-unique-id-from-a-comma-separated-string/#findComment-971051 Share on other sites More sharing options...
rajivgonsalves Posted December 4, 2009 Share Posted December 4, 2009 try this SELECT FIELD_IN_SET( '6', second_theme ) FROM articles Link to comment https://forums.phpfreaks.com/topic/183693-get-a-unique-id-from-a-comma-separated-string/#findComment-971058 Share on other sites More sharing options...
mapleleaf Posted December 4, 2009 Author Share Posted December 4, 2009 SELECT * FROM articles WHERE second_theme IN ( 6 ) ; is what I was looking for. Thanks for the thoughts. I suspect my question wasn't phrased right Link to comment https://forums.phpfreaks.com/topic/183693-get-a-unique-id-from-a-comma-separated-string/#findComment-971069 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.