0 pts.
 Select last 3 transactions
Hello Can someone help me to put together an SQL statement to select the last 3 transactions from a transaction file. In TransactSQL I would do something like this: select top 3 CustID, TransDate, Amount from Trans where CustID= '12345' order by TransDate desc. I believe there must be a more effcient way of getting the latest 3 transactions. Any help would be greatly appreciated. Suhel.

Software/Hardware used:
ASKED: May 22, 2007  6:54 AM
UPDATED: May 15, 2008  5:52 PM

Answer Wiki:
are you looking for an SQL statement to embed in RPG? COBOL? JAVA? or for some other SQL based interface?
Last Wiki Answer Submitted:  May 22, 2007  8:28 am  by  BigKat   7,205 pts.
All Answer Wiki Contributors:  BigKat   7,205 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

Suhel:

Your own solution looks fine to me. Just make sure that CustID and TransDate are indexed to make the query efficient.

Barry

 0 pts.

 

you can add “FETCH FIRST x ROWS ONLY” and “WITH UR”

I beleive that DBq2 V9 has SQL enhancements for this type of query

 40 pts.