Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Row Count in UNION for DB2 1

Status
Not open for further replies.

newdbprgr

Programmer
Oct 21, 2008
6
SG
Faced with this problem, any idea how to go about it?

SELECT * FROM (
(SELECT COL1, COL2, MAX(COL3),
ROWNUMBER() OVER (ORDER BY COL1) AS ROW_NEXT
WHERE COL1 = 'A'
GROUP BY COL1, COL2)
UNION
(SELECT COL1, COL2, COL3,
ROWNUMBER() OVER (ORDER BY COL1) AS ROW_NEXT
WHERE COL1 != 'A'
GROUP BY COL1, COL2, COL3)
) AS TEMP_DATA
WHERE ROW_NEXT BETWEEN upper AND lower; //upper and lower are passed in value for pagination

It returns a seperate set of row number. For example, in set 1 - 1,2,3,4,5,6 and set 2 - 1,2,3

SELECT *,ROWNUMBER() OVER (ORDER BY COL1) AS ROW_NEXT
FROM (
(SELECT COL1, COL2, MAX(COL3)
WHERE COL1 = 'A'
GROUP BY COL1, COL2)
UNION
(SELECT COL1, COL2, COL3
WHERE COL1 != 'A'
GROUP BY COL1, COL2, COL3)
) AS TEMP_DATA
WHERE ROW_NEXT BETWEEN upper AND lower; //upper and lower are passed in value for pagination

Then i tried to take the rownumber out, but 'WHERE ROW_NEXT BETWEEN upper AND lower' condition is not recognised. Any idea to get a continous row count
 
I think that referencing the rownumber() function in the where clause of the outer select is not allowed.
You need an additional nested level..

Ties Blom

 
just as i thought... you've helped to confirm my thought. thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top