Let me preface this question in that while I have a strong background in T-SQL but I am still just a newbie when it comes to DB2.
The root query looks roughly like this:
Select Col1, Col2, Col3 From ( Select A.Col1, B.Col2, B.Col3 From SchemaA.TableA as A Inner Join SchemaA.TableB as B On A.Id = B.ParentId Where A.Col2 = 'TypeValue' Fetch First 5 Rows Only -- This is not allowed in a union or sub select Union Select A.Col1, B.Col2, B.Col3 From SchemaB.TableA as A Inner Join SchemaB.TableB as B On A.Id = B.ParentId Where A.Col2 = 'TypeValue' Fetch First 5 Rows Only -- This is not allowed in a union or sub select ) as Hybrid
Fetch First X Rows is not allowed in subselects or with unions, this isn’t going to work. Since we’re limiting the output, it makes sense to limit the input.
I figure I can achieve a fake union by feeding my subselects into temp tables instead and returning that output instead.
In T-SQL, I can create a temp table on the fly with a query like this how would I do that in DB2?
Select * Into #Temp From TableA
How would I do that in DB2? Or would do I need to create the table before inserting data into it?