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
 

 

How to fetch the first record of each group of records?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
srisyam

New User


Joined: 30 May 2007
Posts: 2
Location: india

PostPosted: Thu Oct 25, 2007 7:45 pm    Post subject: How to fetch the first record of each group of records?
Reply with quote

Hi,

I've a work request for which I need to retrieve the first row of each group of rows.

ColA ColB
a aaaaa
a aaa
b bb
b bbb
c cc
c cccc
c ccc

I want the output as

ColA ColB
a aaaaa
b bb
c cc

Can this be acheived by a single sql statement in DB2? I've tried searching the previous posts without success.

Sri..
Back to top
View user's profile Send private message

Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Thu Oct 25, 2007 8:25 pm    Post subject:
Reply with quote

What defines the FIRST row of each group, is it colB, the order they were entered into the database, or some secret number? First, last, and ect. without something defining the order have not meaning with databases.
Back to top
View user's profile Send private message
srisyam

New User


Joined: 30 May 2007
Posts: 2
Location: india

PostPosted: Fri Oct 26, 2007 9:55 am    Post subject:
Reply with quote

Thank you.

Per my requirement it is enough if it fetches any one row out of the group of rows and It worked using the following query

SELECT DISTINCT COLA,MIN(COLB)
FROM TABLE
GROUP BY COLA

Regards, Sri..
Back to top
View user's profile Send private message
shashikalayellenki

New User


Joined: 15 Oct 2007
Posts: 1
Location: chennai

PostPosted: Fri Oct 26, 2007 1:47 pm    Post subject: I need to retrieve the first row of each group of rows.
Reply with quote

we can use fetch first one rows only in the cursor then we get the result right .
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 Record Not found in AlX but record re... mukun264 COBOL Programming 2 Fri Mar 24, 2017 9:28 am
No new posts Count the length of the record & ... sreekusr DFSORT/ICETOOL 4 Thu Mar 23, 2017 7:52 pm
No new posts Why TS/OP would Not contact site supp... RahulG31 All Other Mainframe Topics 2 Wed Mar 22, 2017 7:46 am
No new posts IMS DB-How to update a record (a sing... Nic Clouston IMS DB/DC 9 Thu Mar 09, 2017 4:38 pm
No new posts Join giving more records than expected Danielle.Filteau SYNCSORT 2 Thu Mar 09, 2017 3:28 am


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