-4

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

我当前的代码:

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

6 回答 6

4
SELECT ShortName FROM product WHERE Active = 1 OR ShortName LIKE 'BlueBall%'
于 2012-12-18T11:59:22.097 回答
3
SELECT ShortName FROM product WHERE Active = 1 AND ShortName LIKE 'BlueBall%'
于 2012-12-18T11:59:23.540 回答
0
SELECT ShortName FROM product WHERE Active = 1 OR ShortName LIKE 'BlueBall%'

会工作。 http://w3schools.com/sql/sql_like.asp

于 2012-12-18T12:05:53.477 回答
0

您需要使用这样的like条件:

$query = "SELECT ShortName FROM product WHERE Active = 1 AND ShortName like 'BlueBall%'";
于 2012-12-18T11:59:55.477 回答
0
SELECT ShortName FROM product WHERE Active = 1 AND ShortName LIKE "BlueBall%"

见:http ://dev.mysql.com/doc/refman/5.0/en/pattern-matching.html

于 2012-12-18T12:00:30.280 回答
0

只需where使用 OR 运算符将名称添加到子句
以下是重写的查询:

$query = "SELECT ShortName FROM product WHERE Active = 1 OR name like 'BlueBall%';
于 2012-12-18T12:00:52.277 回答