mysql多个SELECT语句

时间:2015-07-27 16:52:57

标签: php mysql

我有这个dbtable

--------------------------------------------------------
id                | image                   | category
--------------------------------------------------------
 1                | image 1                 | boy
 2                | image 2                 | girl
 3                | image 3                 | girl
 4                | image 4                 | boy
 5                | image 5                 | girl
--------------------------------------------------------

我正在尝试从表中选择所有ID> 1和< 4和类别是='女孩'但我不能做对。这是我的php

$query = "SELECT * FROM dbtable where id>1 and id<4 and where category = 'girl'";

和这个

$query = "SELECT * FROM news where id>1 and id<4 and cathegory = 'business'";

非正在运作

2 个答案:

答案 0 :(得分:1)

尝试

$query = "SELECT * FROM dbtable where id>1 and id<4 and category = 'girl'";

答案 1 :(得分:1)

如果您想要在特定范围内的值,则可以在两者之间使用:

$query = "SELECT * FROM dbtable where category = 'girl' and id between 1 and 4";

SQL Fiddle Demo