我有一个从数据库中选择活动项目的语句,但我也想让它选择以名称 BlueBall 开头的项目。
我当前的代码:
$query = "SELECT ShortName FROM product WHERE Active = 1";
SELECT ShortName FROM product WHERE Active = 1 OR ShortName LIKE 'BlueBall%'
SELECT ShortName FROM product WHERE Active = 1 AND ShortName LIKE 'BlueBall%'
SELECT ShortName FROM product WHERE Active = 1 OR ShortName LIKE 'BlueBall%'
您需要使用这样的like
条件:
$query = "SELECT ShortName FROM product WHERE Active = 1 AND ShortName like 'BlueBall%'";
SELECT ShortName FROM product WHERE Active = 1 AND ShortName LIKE "BlueBall%"
见:http ://dev.mysql.com/doc/refman/5.0/en/pattern-matching.html
只需where
使用 OR 运算符将名称添加到子句
以下是重写的查询:
$query = "SELECT ShortName FROM product WHERE Active = 1 OR name like 'BlueBall%';