Question

  Asked: May 22 2007   6:54 AM GMT
  Asked by: SuhelAC


Select last 3 transactions


DB2 universal database, PC/Windows Connectivity, Data analysis, Data warehousing applications, Database, Oracle, DB2, SQL, Development

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.

Subscribe to Alerts! Get questions and answers delivered to your Inbox.


E-mail me updates on this question



   SUBSCRIBE

hidden modal window

Answer Wiki (Improve, edit or add to this answer)


 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0



are you looking for an SQL statement to embed in RPG? COBOL? JAVA? or for some other SQL based interface?
  • AddThis Social Bookmark Button

Browse more Questions and Answers on Database, Microsoft Windows and DataManagement.

Looking for relevant Database Whitepapers? Visit the SearchOracle.com Research Library.


Discuss This Answer


You must be logged-in to discuss a question. Log-in/Register

BarryCummings  |   May 22 2007  9:44AM GMT

Suhel:

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

Barry

 

DB2 DBA  |   May 15 2008  5:52PM GMT

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

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