Der er flere måder at få den tidligste post og undgå at skulle indtaste de samme kriterier to gange.
Brug af FETCH FIRST ROWS (tilgængelig fra 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;
Brug af en CTE (WITH-klausul)
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);
Brug af vinduesfunktioner
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;
(Jeg har i øvrigt ændret tilslutningskriterierne i alle disse forespørgsler. Det virker bare ekstremt usandsynligt, at du vil deltage på abc_customer_details.id = abc_customers.customer_id
.)