我想在一个查询中获取一个帖子以及与该帖子关联的第一条评论。这是我在 PostgreSQL 中的操作方式:
SELECT p.post_id,
(select * from
(select comment_body from comments where post_id = p.post_id
order by created_date asc) where rownum=1
) the_first_comment
FROM posts p
它工作正常。
但是,在 Oracle 中,我收到错误 ORA-00904 p.post_id: invalid identifier。
它似乎对一个子选择工作正常,但由于我需要使用 rownum (在 Oracle 中没有限制/偏移),我无法获得只有一个的评论。
我在这里做错了什么?