IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

to extract certain number of records from the table.


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
prabhucs01
Warnings : 1

New User


Joined: 07 Mar 2005
Posts: 43

PostPosted: Mon Sep 14, 2009 9:33 am
Reply with quote

if there is a table with huge number of records and if i want to extract only first 3 records from the table, what query i have to provide to retreive first 3 records. no specific where conditions provided.
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Mon Sep 14, 2009 10:08 am
Reply with quote

Quote:
if there is a table with huge number of records

They are not called as records. They are ROWS
Give
Code:
FETCH FIRST 3 ROWS ONLY
after your query.. icon_smile.gif
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Mon Sep 14, 2009 4:49 pm
Reply with quote

Use ORDER By along with what Sambhaji has suggested, otherwise you may get inconsistent results.
Back to top
View user's profile Send private message
lkhiger

New User


Joined: 28 Oct 2005
Posts: 89

PostPosted: Mon Sep 14, 2009 5:13 pm
Reply with quote

If you use V9 you can do following

Code:
select * from
(select t1.*, rownumber() over()  colno from table t1) t2
where colno <= exactNo


Lenny
Back to top
View user's profile Send private message
Ketan Varhade

Active User


Joined: 29 Jun 2009
Posts: 197
Location: Mumbai

PostPosted: Mon Sep 14, 2009 5:22 pm
Reply with quote

Hi Lenny,
The query posted by you is quite confusing to me, Its better to provide a easy and understandable query to the OP,
I didnt got a word from the query what you have posted even my shop has V9, still.
What Anuj has said will get the desired result what OP wants.

Thanks
Back to top
View user's profile Send private message
lkhiger

New User


Joined: 28 Oct 2005
Posts: 89

PostPosted: Mon Sep 14, 2009 5:38 pm
Reply with quote

Ketan Varhade wrote:
Hi Lenny,
The query posted by you is quite confusing to me, Its better to provide a easy and understandable query to the OP,
I didnt got a word from the query what you have posted even my shop has V9, still.
What Anuj has said will get the desired result what OP wants.

Thanks

No problem. I just shown an another way.

Lenny
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Load new table with Old unload - DB2 DB2 6
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Need help for File Aid JCL to extract... Compuware & Other Tools 23
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Substring number between 2 characters... DFSORT/ICETOOL 2
Search our Forums:

Back to Top