Ada beberapa cara untuk mendapatkan catatan paling awal dan menghindari keharusan mengetik kriteria yang sama dua kali.
Menggunakan FETCH FIRST ROWS (tersedia pada Oracle 12c)
select *
from abc_customer_details cd
join abc_customers c on c.id = cd.customer_id
where cd.country_code = 'KE'
order by creation_timestamp
fetch first row only;
Menggunakan CTE (klausa DENGAN klausa)
with cte as
(
select *
from abc_customer_details cd
join abc_customers c on c.id = cd.customer_id
where cd.country_code = 'KE'
)
select *
from cte
where (creation_timestamp) = (select min(creation_timestamp) from cte);
Menggunakan fungsi jendela
select *
from
(
select cd.*, c.*, min(creation_timestamp) over () as min_creation_timestamp
from abc_customer_details cd
join abc_customers c on c.id = cd.customer_id
where cd.country_code = 'KE'
)
where creation_timestamp = min_creation_timestamp;
(Omong-omong, saya mengubah kriteria bergabung di semua kueri ini. Tampaknya sangat tidak mungkin Anda ingin bergabung di abc_customer_details.id = abc_customers.customer_id
.)