snorky Posted September 3, 2010 Share Posted September 3, 2010 mysql select ... where ... in or like Consider these statements: Code: select * from[i] sometable[/i] where[i] thiscolumn[/i] in(1,2,3); That returns all rows where column thiscolumn is one of those three values. Code: select * from [i]sometabl[/i]e where [i]thiscolumn[/i] like("a%"); That returns all rows where the first character of a column thiscolumn is 'a'; What I'm trying to do is to combine the two concepts as in something like select * from [i]sometable[/i] where [i]thiscolumn[/i] in('like("b%")','like("c%")'); I'm trying to return all rows where the first character of a column thiscolumn is 'b' or 'c'; That syntax is wrong. I've tried assigning variables set @var1: 'like="b%"'; set @var2: 'like="c%"'; then using those vars in the in predicate. select * from [i]sometable[/i] where [i]thiscolumn[/i] in('b','c'); Again, bad syntax. I could use ... Code: thiscolumn like("b%") or thiscolumn like("c%") or thiscolumn like("da%") or .... ... ad nausem. But if there are many values in the set, it becomes quite clunky. I've tried the mysql manual and google. The problem with those is trying to figure out how to ask the question. A forum like this gives me the ability to (hopefully)seek, explain, and find the solution. In this case I don't have the luxury of using php; I have to do it within mysql. Ideas? __________________ Certified Digital Forensics Examiner, MCSE, etc., etc. Nature: Nerd. Nurture:Linux Quote Link to comment https://forums.phpfreaks.com/topic/212468-mysql-selectwhere-statements-using-in-and-and-like/ Share on other sites More sharing options...
mikosiko Posted September 4, 2010 Share Posted September 4, 2010 mixing IN and LIKE .... not possible as far as I'm aware of ... syntax for both clause are very clear. seems to me that you are looking to do something for what REGEXP is more suitable... look the examples and sure you will find the answer http://dev.mysql.com/doc/refman/5.1/en/regexp.html something like WHERE thiscolumn REGEXP "expr1 | expr2 | expr3... etc" where "expr?" is a formal regular expresion. hope this help Quote Link to comment https://forums.phpfreaks.com/topic/212468-mysql-selectwhere-statements-using-in-and-and-like/#findComment-1107056 Share on other sites More sharing options...
mikosiko Posted September 4, 2010 Share Posted September 4, 2010 you also can search for examples here http://www.phpfreaks.com/forums/index.php/board,43.0.html Quote Link to comment https://forums.phpfreaks.com/topic/212468-mysql-selectwhere-statements-using-in-and-and-like/#findComment-1107063 Share on other sites More sharing options...
snorky Posted September 5, 2010 Author Share Posted September 5, 2010 you also can search for examples here http://www.phpfreaks.com/forums/index.php/board,43.0.html (whacks self upside the head) Regex ! Of course! I spent hours going down the wrong path, running down a ditch. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/212468-mysql-selectwhere-statements-using-in-and-and-like/#findComment-1107390 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.