0

我想构建一个mysql_query只给我一个新rows 插入的table带有一个where condition类似的......

SELECT (LAST 5) FROM `x`  WHERE `USER_KEY` = '$RK' ORDER BY `dd` DESC 

之后这些数据将在 json 中解析,否则我只会得到所有数据并循环抛出。

4

1 回答 1

2

您可以颠倒顺序并获得前 5 个。这与获得最后 5 个并反过来排序相同

SELECT * FROM `x`  WHERE `USER_KEY` = '$RK' ORDER BY `dd` ASC limit 5

或者,如果您需要 desc 命令,您可以执行

select * from (SELECT * FROM `x`  
               WHERE `USER_KEY` = '$RK' 
               ORDER BY `dd` asc 
               limit 5) as x 
order by `dd` desc
于 2012-05-12T05:26:42.367 回答