2

我有类似的东西,$SQL = "SELECT * FROM profile_comments WHERE name = '$username' LIMIT $offset, $rowsperpage";但我想知道是否可以仅针对某一列的空行限制结果?

示例

$SQL = "SELECT * FROM profile_comments WHERE name = '$username' LIMIT table is NULL 5, 10"; 

profile_comments

id | parent_id |  name |    text    | datetime
-------------------------------------------------
 1 |   null    | Netra |  Bla bla   | 00.00.0000
 2 |    1      | Netra |  Bla bla   | 00.00.0000
 3 |    1      | Netra |  Bla bla   | 00.00.0000
 4 |   null    | Netra |  Bla bla   | 00.00.0000
 5 |    4      | Netra |  Bla bla   | 00.00.0000
4

1 回答 1

4

您需要在WHERE子句中添加该条件,而不是在限制子句之后。这个怎么样?

$SQL = "SELECT * 
        FROM profile_comments 
        WHERE name = '$username' AND  
              `table` is NULL 
        LIMIT 5, 10";

答案:

SELECT * FROM profile_comments WHERE PARENT_ID IS NOT NULL UNION SELECT * FROM profile_comments WHERE PARENT_ID IS NULL GROUP BY PARENT_ID;

于 2012-09-02T22:20:16.153 回答