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? Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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" Quote Link to comment Share on other sites More sharing options...
fenway Posted March 10, 2011 Share Posted March 10, 2011 FIND_IN_SET(), perhaps. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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 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.