0

当我运行此查询时,Oracle 给我一个错误(ORA-00907:缺少右括号):

select * 
from reason_for_appointment 
where reason_for_appointment_id in 
(
    select reason_for_appointment_id 
    from appointment_reason 
    where appointment_id = 11 
    order by appointment_reason_id
)

但是,当我只运行子查询时,没有错误。

谁能解释问题是什么?

4

5 回答 5

11

内部查询结果将永远不会显示,因此在嵌套选择中进行排序是没有意义的。而是将其应用于外部查询。

于 2008-10-29T19:13:16.440 回答
3

问题是在这样的子查询中不允许使用 ORDER BY。你为什么想要一个?

于 2008-10-29T21:40:15.457 回答
1

看起来您希望使用在另一个表中定义的顺序来显示一个表的结果。内部连接就足够了。

select reason_for_appointment.*
from reason_for_appointment rfa, appointment_reason ar
where rfa.reason_for_appointment_id = ar.reason_for_appointment_id
and ar.appointment_id = 11
order by ar.appointment_reason_id;
于 2008-10-30T00:42:12.517 回答
0

select * from reason_for_appointment where reason_for_appointment_id in (select reason_for_appointment_id fromointment_reason whereointment_id = 11 order by modify_reason_id)

尝试类似:使用辅助作为(从约会原因中选择reason_for_appointment_id,其中约会ID = 11按约会原因ID订购)从约会原因中选择reason_for_appointment_id where reason_for_appointment_id in(从辅助中选择reason_for_appointment_id)

于 2009-01-20T14:10:50.087 回答
0

如果您的目标是对输出进行排序,您只需将 ORDER BY 移到子查询之外:

select * from reason_for_appointment where reason_for_appointment_id in
 (select reason_for_appointment_id from appointment_reason where appointment_id = 11)
 order by reason_for_appointment_id

(我假设你写“appointment_reason_id”的地方是“reason_for_appointment_id”。如果真的有两个不同的列有这些名字......哎呀。)

于 2009-01-20T16:16:17.167 回答