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 SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
No new posts Removing Duplicates based on certain ... chandracdac DFSORT/ICETOOL 8 Fri Dec 09, 2016 4:40 am
No new posts Limit duplicate records in the SORT pshongal SYNCSORT 6 Mon Nov 21, 2016 12:54 pm
No new posts How to split the records using the am... vnktrrd DFSORT/ICETOOL 24 Fri Oct 28, 2016 7:33 pm
No new posts Sort records based on numeric field. Alks SYNCSORT 2 Wed Oct 19, 2016 10:14 pm


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