MySql选择,需要添加到我的语句中

时间:2012-12-18 11:57:49

标签: php mysql select

我有一个声明从数据库中选择活动项目,但我还想让它选择以名称BlueBall开头的项目。

我目前的代码:

$query = "SELECT ShortName FROM product WHERE Active = 1";

6 个答案:

答案 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%'

会奏效。  http://w3schools.com/sql/sql_like.asp