Subject Select for take first record from tableB for each record in tableA
Author emb_blaster
Hi all,
I was searching for a way to achieve the same result
as aggregate function first(column). Example:

I had a Customer table, and a Sales table so I wish to
Select the Sales with Customers that din´t payed the bill :) and
the bill was 30 days old.
Now is the problem, I want only the oldest bill.

So, I´m doing this:

select, SS.*, (current_date - as DelayedDays
from customer C
inner join Sales SS on C.ID = SS.IDCustomer
where SS.PKSales = (select first 1 stemp.PKSales
from Sales stemp
where (stemp.PayDate is null) and (current_date - > 30 ) and (stemp.IDCustomer = C.ID)
order by (
order by

Using FB 2.0 there´s a way to simplify or optimize this query?
I don´t believe that I´m doing the rigth way this time,
... but still don´t know why ;)