Hello guys,
When i use the common-table-expression keyword WITH, where does the defined data reside? or DB2 just replaces the WITH table with the sql?
for example
with mytable as (select * from sysibm)
Select * from mytable
In DB2 v10, is there an easy way (like in oracle) to define father-child reletionship? or it is just a recursive function with the WITH clause.
Thanks alot,
P.S
Anyone encountered -725 sql error while rebinding the DRDA protocol?
Question about common table expression and father-child
-
- Posts: 17
- Joined: Fri Jul 08, 2022 7:29 pm
- Skillset: leblesmoutilabiskouti
- Referer: leblesmoutilabiskouti
Re: Question about common table expression and father-child
This is an old question, but I'm going to answer it anyway, because many people still ask themselves the same question today.
A Common Table Expression (CTE) is simply an externalized derived table.
For example, instead of writing :
you may write :
the advantages are :
It is also important to know that CTEs are the only solution for writing recursive queries.
Because CTE is only a derived table, there are no specific storage consideration. Data are only stored in the tables and buffered in RAM as usual.
A Common Table Expression (CTE) is simply an externalized derived table.
For example, instead of writing :
Code: Select all
select Col1
, Col2
, [...]
, Coln
from (select ColA as Col1
, ColB as Col2
, [...]
, ColX as Coln
from My_view
) as Derived_table
you may write :
Code: Select all
with Derived_table as
(select ColA as Col1
, ColB as Col2
, [...]
, ColX as Coln
from My_view
)
select Col1
, Col2
, [...]
, Coln
from Derived_table
the advantages are :
- the possible mutualization of the derived table when it is used several times in the same query
- the simplification of the writing of the main query
It is also important to know that CTEs are the only solution for writing recursive queries.
Because CTE is only a derived table, there are no specific storage consideration. Data are only stored in the tables and buffered in RAM as usual.
- sergeyken
- Posts: 458
- Joined: Wed Jul 24, 2019 10:12 pm
- Skillset: Assembler, JCL, Utilities, PL/I, C/C++, DB2, SQL, REXX, COBOL, etc. etc. etc.
- Referer: Internet search
Re: Question about common table expression and father-child
CTE from WITH clause can be considered as "local VIEW definition".
It works almost in the same manner as regular VIEW, but it only exists during the query execution where its corresponding WITH clause located.
It works almost in the same manner as regular VIEW, but it only exists during the query execution where its corresponding WITH clause located.
Javas and Pythons come and go, but JCL and SORT stay forever.
-
- Similar Topics
- Replies
- Views
- Last post
-
- 12
- 3875
-
by sergeyken
View the latest post
Wed Jan 29, 2025 8:49 pm
-
-
FORMAT THE FILE SO ALL CHILD UNDER SAME PARENT IN ONE LINE
by azhar » Wed May 31, 2023 4:27 pm » in JCL - 1
- 1752
-
by sergeyken
View the latest post
Thu Jun 01, 2023 3:06 am
-
-
- 1
- 1565
-
by cobol_dev
View the latest post
Thu Apr 14, 2022 12:55 am
-
- 2
- 2255
-
by Pedro
View the latest post
Tue Feb 27, 2024 4:44 am
-
- 0
- 3042
-
by dylson
View the latest post
Sat Aug 01, 2020 11:09 pm