Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
to extract certain number of records from the table.

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: to extract certain number of records from the table.
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    Post subject:
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

Senior Member


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

PostPosted: Mon Sep 14, 2009 4:49 pm    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Update table without cursor Ron Klop DB2 3 Wed Oct 11, 2017 1:06 pm
No new posts Table(Unicode(Graphic) table) loading... muralikrishnan_new DB2 0 Thu Oct 05, 2017 5:10 pm
No new posts sort records based on length exceeds ... maxsubrat DFSORT/ICETOOL 7 Wed Oct 04, 2017 4:48 pm
No new posts Addition of two records on 2 fields amar143 SYNCSORT 8 Tue Oct 03, 2017 11:14 am
No new posts Spool Extract for Z /os 1.04 version Khadhar Basha CLIST & REXX 3 Thu Sep 28, 2017 3:14 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us