View previous topic :: View next topic
|
Author |
Message |
srisyam
New User
Joined: 30 May 2007 Posts: 2 Location: india
|
|
|
|
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 |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
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 |
|
|
srisyam
New User
Joined: 30 May 2007 Posts: 2 Location: india
|
|
|
|
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 |
|
|
shashikalayellenki
New User
Joined: 15 Oct 2007 Posts: 1 Location: chennai
|
|
|
|
we can use fetch first one rows only in the cursor then we get the result right . |
|
Back to top |
|
|
|