MDanz Posted March 9, 2011 Share Posted March 9, 2011 a column in mysql has "test, a1, a2, a3".. in the select query how do i select a column that has "test" in it? Link to comment https://forums.phpfreaks.com/topic/230116-mysql-select-query-help/ Share on other sites More sharing options...
TOA Posted March 9, 2011 Share Posted March 9, 2011 I think this is what you're asking for: http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html Link to comment https://forums.phpfreaks.com/topic/230116-mysql-select-query-help/#findComment-1185213 Share on other sites More sharing options...
MDanz Posted March 9, 2011 Author Share Posted March 9, 2011 for example.. in one column it has "test1, test2, test3, test4" .... when i search for test1... i only want rows that have 'test1' in them. $search = test1 i've tried LIKE %$test1% but it get's all rows with the word 'test' in it... i want only rows with the word 'test1' in it. Link to comment https://forums.phpfreaks.com/topic/230116-mysql-select-query-help/#findComment-1185217 Share on other sites More sharing options...
TOA Posted March 9, 2011 Share Posted March 9, 2011 Oh if you want an exact match, just use = WHERE Column_Name = "Search_Term" Is that what you need? Link to comment https://forums.phpfreaks.com/topic/230116-mysql-select-query-help/#findComment-1185219 Share on other sites More sharing options...
MDanz Posted March 10, 2011 Author Share Posted March 10, 2011 Oh if you want an exact match, just use = WHERE Column_Name = "Search_Term" Is that what you need? but what if in the column it has "test1, test2, test3".. i can't use column_name="search_term" Link to comment https://forums.phpfreaks.com/topic/230116-mysql-select-query-help/#findComment-1185326 Share on other sites More sharing options...
fenway Posted March 10, 2011 Share Posted March 10, 2011 FIND_IN_SET(), perhaps. Link to comment https://forums.phpfreaks.com/topic/230116-mysql-select-query-help/#findComment-1185335 Share on other sites More sharing options...
MDanz Posted March 10, 2011 Author Share Posted March 10, 2011 i used LIKE $search% and it worked. thanks anyway Link to comment https://forums.phpfreaks.com/topic/230116-mysql-select-query-help/#findComment-1185340 Share on other sites More sharing options...
fenway Posted March 10, 2011 Share Posted March 10, 2011 i used LIKE $search% and it worked. thanks anyway That's not a robust solution. Link to comment https://forums.phpfreaks.com/topic/230116-mysql-select-query-help/#findComment-1185342 Share on other sites More sharing options...
TOA Posted March 10, 2011 Share Posted March 10, 2011 i used LIKE $search% and it worked. thanks anyway Double check that. If you search for test2 in your query, you won't return correct results. It only returns the right results if you use the first term with your query. I just created a table and tried it. You need a % in front too, like I originally suggested i've tried LIKE %$test1% but it get's all rows with the word 'test' in it... i want only rows with the word 'test1' in it. No, that should return the right results: anything with test1 in it Link to comment https://forums.phpfreaks.com/topic/230116-mysql-select-query-help/#findComment-1185587 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.