我有一个声明从数据库中选择活动项目,但我还想让它选择以名称BlueBall开头的项目。
我目前的代码:
$query = "SELECT ShortName FROM product WHERE Active = 1";
答案 0 :(得分:4)
SELECT ShortName FROM product WHERE Active = 1 OR ShortName LIKE 'BlueBall%'
答案 1 :(得分:3)
SELECT ShortName FROM product WHERE Active = 1 AND ShortName LIKE 'BlueBall%'
答案 2 :(得分:0)
您需要使用like
这样的条件:
$query = "SELECT ShortName FROM product WHERE Active = 1 AND ShortName like 'BlueBall%'";
答案 3 :(得分:0)
SELECT ShortName FROM product WHERE Active = 1 AND ShortName LIKE "BlueBall%"
请参阅:http://dev.mysql.com/doc/refman/5.0/en/pattern-matching.html
答案 4 :(得分:0)
只需使用OR运算符为where
子句添加名称
这是重写的查询:
$query = "SELECT ShortName FROM product WHERE Active = 1 OR name like 'BlueBall%';
答案 5 :(得分:0)
SELECT ShortName FROM product WHERE Active = 1 OR ShortName LIKE 'BlueBall%'