This table stores data for who bought which book and when. I want to know which books were bought first by USERID #1. SQL fiddle
That would result in
USERID BOOKID DATE_PURCHASE
1 2 2014-03-22 (purchased only by USERID #1)
1 5 2014-03-29 (purchased earlier than USERID #2)
1 6 2014-03-28 (purchased earlier than USERID #3)
1 7 2014-03-26 (purchased earlier than USERID #3)
It doesn't show BOOKID #3 because that book was purchased first by USERID #2.
Please note the table may consist tens of thousands of rows so I need an efficient solution.
If had to do it manually I would do this:
1. Check what books did USERID #1 buy
2. Go through all rows with those books (BOOKID) and check the MIN(DATE_PURCHASE) for each row
3. Write out those rows only where the USERID = #1