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

内部クエリの結果は表示されないため、ネストされた選択で order by を実行しても意味がありません。代わりに、外側のクエリに適用してください。

于 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 frompointment_reason wherepointment_id = 11 order bypointment_reason_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」を意味していると思います。これらの名前を持つ2つの異なる列が実際にある場合...痛い。)

于 2009-01-20T16:16:17.167 に答える