这个SQL查询给了我想要的结果;但是,我希望结果按不同的列排序:
SELECT *
FROM post
INNER JOIN account ON post.account_id = account.account_id
WHERE post_id > new
ORDER BY post_date
ASC LIMIT 10;
我不能简单地将ORDER BY post_date ASC
更改为ORDER BY post_id DESC
,而事实上我会按照我想要的方式对查询进行排序......它会给我错误的10个帖子。
我只想采用上述查询的 EXACT RESULTS ,然后按post_id
重新排序结果。
如果可能的话我想用SQL做这个,如果没有,我可以通过将结果添加到一个新的数组中来排序结果。
答案 0 :(得分:6)
使用子查询重新排序:
SELECT * FROM (
SELECT *
FROM post
INNER JOIN account ON post.account_id = account.account_id
WHERE post_id > neww
ORDER BY post_date ASC LIMIT 10;
) ORDER BY post_id
答案 1 :(得分:4)
使用子查询:
SELECT * FROM (
SELECT *
FROM post
INNER JOIN account
ON post.account_id = account.account_id
WHERE post_id > neww
ORDER BY post_date ASC
LIMIT 10) AS T1
ORDER BY post_id DESC