How can I use Select Count(*)
in Fetch First
or will be another way to limit the result length.
Table A
PK |
---|
1 |
Table B
PK |
---|
1 |
2 |
WITH ALL_DATA AS
(SELECT *
FROM TABLE_A
)
SELECT *
FROM TABLE B
FETCH FIRST (SELECT COUNT(*) FROM WITH ALL_DATA) ROWS ONLY
)
I am expecting the first row with item 1 from Table B. I am using DB2 LUW.
The syntax could be slightly different.
You may enumerate the B
rows first and use their number in the WHERE
clause.
WITH ALL_DATA AS
(SELECT *
FROM (VALUES 1, 2) A (I)
)
SELECT I
FROM
(
SELECT B.*, ROW_NUMBER () OVER () AS RN_
FROM (VALUES 1, 2, 3) B (I)
)
WHERE RN_ <= (SELECT COUNT(*) FROM ALL_DATA)
I |
---|
1 |
2 |