Zde je klíčové slovo PRVNÍ . Můžete použít analytickou funkci FIRST_VALUE nebo agregační konstrukce FIRST .
Pro FIRST nebo LAST výkon není nikdy horší a často lepší než ekvivalentní FIRST_VALUE nebo LAST_VALUE konstrukt, protože nemáme nadbytečné řazení oken a v důsledku toho nižší náklady na provedení:
select table_A.id, table_A.name, firstFromB.city
from table_A
join (
select table_B.id2, max(table_B.city) keep (dense_rank first order by table_B.city) city
from table_b
group by table_B.id2
) firstFromB on firstFromB.id2 = table_A.id
where 1=1 /* some conditions here */
;
Od 12c zaveden operátor LATERAL a také CROSS/OUTER APPLY spojení, umožňují použít korelovaný poddotaz na pravé straně JOIN klauzule:
select table_A.id, table_A.name, firstFromB.city
from table_A
cross apply (
select max(table_B.city) keep (dense_rank first order by table_B.city) city
from table_b
where table_B.id2 = table_A.id
) firstFromB
where 1=1 /* some conditions here */
;