我有这个 mysql 查询,我只想查询我的 SELECT 语句的最后 3 行,并且我想再次将我的查询重新排序为 ASC 顺序,因为子查询在 DESC 中。
SELECT * FROM(
SELECT *
FROM post_replies
WHERE post_replies.post_hash=:posthash
ORDER BY post_replies.reply_id DESC
LIMIT 3)
ORDER BY reply_id ASC
这是出现的错误
CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1248 Every derived table must have its own alias. The SQL statement executed was: SELECT * FROM( SELECT * FROM post_replies WHERE post_replies.post_hash=:posthash ORDER BY post_replies.reply_id DESC LIMIT 3) ORDER BY reply_id ASC
我不明白如何将 mysql 别名按定义放在这里 here
我怎样才能让我的查询只获取我的 select 语句的最后 3 行,并使结果按 ASC 顺序排列?
最佳答案
错误只是告诉您需要调用您的子选择。您将别名放在子选择之后的右括号之后。这应该有效:
SELECT a.* FROM(
SELECT *
FROM post_replies
WHERE post_replies.post_hash=:posthash
ORDER BY post_replies.reply_id DESC
LIMIT 3) a
ORDER BY a.reply_id ASC
关于mysql - 获取 SELECT 语句中的最后 3 行并使其成为 ASC 顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10168194/