MySQL IN with LIKE

前端 未结 3 2058
忘了有多久
忘了有多久 2020-12-11 09:46

How would I use a IN table with like? So that I could use % in them? By in I mean:

SELECT fields 
  FROM table 
 WHERE age = \"50\" 
   AND name IN (\"tim\         


        
3条回答
  •  醉梦人生
    2020-12-11 10:19

    You can use a number of LIKE expressions:

    SELECT fields 
      FROM table 
      WHERE age = "50" 
            AND (
                 name LIKE "2010-09-17%" 
                 OR name LIKE "2010-09-16%"
                );
    

    or you can use a regex:

    SELECT fields 
      FROM table 
     WHERE age = "50" 
           AND name REGEXP "2010-09-17.*|2010-09-16.*";
    

    or, cleverly

    SELECT fields 
      FROM table 
     WHERE age = "50" 
           AND name REGEXP "2010-09-1(6|7).*";
    

提交回复
热议问题