Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups 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 what is meaning of the number in dcl Martylin PL/I & Assembler 2 Thu Mar 09, 2017 7:18 am
No new posts Join giving more records than expected Danielle.Filteau SYNCSORT 2 Thu Mar 09, 2017 3:28 am
No new posts TSO or command line utility to genera... kishpra JCL & VSAM 3 Thu Mar 09, 2017 1:11 am
No new posts Extract set of records matching on ac... bhaskar_kanteti DFSORT/ICETOOL 3 Mon Mar 06, 2017 7:19 am
No new posts GDG version number PANDU1 JCL & VSAM 4 Sat Mar 04, 2017 8:28 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us