This SQL query gives me the results I want; however, I want the results ordered by a different column:
SELECT *
FROM post
INNER JOIN account ON post.account_id = account.account_id
WHERE post_id > new
ORDER BY post_date
ASC LIMIT 10;
I can not simply change ORDER BY post_date ASC
to ORDER BY post_id DESC
, while that will in fact order the query the way I want it... it will give me the wrong 10 posts.
I simply want to take the EXACT RESUL开发者_如何学JAVATS of the above query then reorder the results by the post_id
.
Use a subquery to reorder:
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
Use a subquery:
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
精彩评论