MySQL LIKE IN()?

后端 未结 11 1992
时光说笑
时光说笑 2020-11-22 05:31

My current query looks like this:

SELECT * FROM fiberbox f WHERE f.fiberBox LIKE \'%1740 %\' OR f.fiberBox LIKE \'%1938 %\' OR f.fiberBox LIKE \'%1940 %\'
         


        
11条回答
  •  忘掉有多难
    2020-11-22 05:50

    You can create an inline view or a temporary table, fill it with you values and issue this:

    SELECT  *
    FROM    fiberbox f
    JOIN    (
            SELECT '%1740%' AS cond
            UNION ALL
            SELECT '%1938%' AS cond
            UNION ALL
            SELECT '%1940%' AS cond
            ) с
    ON      f.fiberBox LIKE cond
    

    This, however, can return you multiple rows for a fiberbox that is something like '1740, 1938', so this query can fit you better:

    SELECT  *
    FROM    fiberbox f
    WHERE   EXISTS
            (
            SELECT  1
            FROM    (
                    SELECT '%1740%' AS cond
                    UNION ALL
                    SELECT '%1938%' AS cond
                    UNION ALL
                    SELECT '%1940%' AS cond
                    ) с
            WHERE   f.fiberbox LIKE cond
            )
    

提交回复
热议问题