MySQL的声明 - 添加另一个条件

时间:2015-07-14 19:17:53

标签: mysql

我使用以下语句:

$statement = mysql_query("SELECT * FROM  `my_table` WHERE 
             `name` LIKE '%".$searchVal."%'
            || `street` LIKE '%".$searchVal."%'
            || `description` LIKE '%".$searchVal."%'
            || `longname` LIKE '%".$searchVal."%'  
                            ORDER BY id");

我想添加另一个条件,只搜索type = 500,600,700,800

1 个答案:

答案 0 :(得分:1)

||是一个连接运算符,我认为您打算使用OR条件,如

SELECT * FROM  `my_table`  
            WHERE (`name` LIKE '%".$searchVal."%'
            OR `street` LIKE '%".$searchVal."%'
            OR `description` LIKE '%".$searchVal."%'
            OR `longname` LIKE '%".$searchVal."%')
            AND `type` IN (500,600,700,800) <-- extra condition
            ORDER BY id;