In a firebird database with a table \"Sales\", I need to select the first sale of all customers. See below a sample that show the table and desired result of query.
Search for the sales with no earlier sales:
SELECT S1.* FROM SALES S1 LEFT JOIN SALES S2 ON S2.CUSTOMERID = S1.CUSTOMERID AND S2.DTHRSALE < S1.DTHRSALE WHERE S2.ID IS NULL
Define an index over (customerid, dthrsale) to make it fast.