Home > Ask the Oracle Experts > Questions & Answers > Last N rows in DB2
Ask The Oracle Expert: Questions & Answers
EMAIL THIS

Last N rows in DB2

Rudy Limeback EXPERT RESPONSE FROM: Rudy Limeback

Pose a Question
Other Oracle Categories
Meet all Oracle Experts
Become an Expert for this site
>
QUESTION POSED ON: 03 October 2002
Suppose a file in AS/400 DB2 has 1000 records. How can I retrieve the last 100 rows from the file?

>
EXPERT RESPONSE

This is an interesting twist on the usual "Top N" query question. There are two parts to the answer. First, you can get the last N simply by running a Top N query which includes an ORDER BY clause with the DESCENDING keyword.

Second, since DB2 is one of the databases which has implemented special syntax just for the purpose of this type of query (others being Microsoft SQL Server and Access with TOP and MySQL and PostgreSQL with LIMIT), you simply utilize that syntax. According to the DB2 Universal Database for iSeries SQL Reference page for the select-statement, this would be

select foo, bar
  from yourAS400table
order by foo descending
fetch first 100 rows only

For More Information


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice

HomeNewsTopicsTipsAsk the ExpertsMultimediaWhite PapersProductsBlogs
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 2003 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts