Introduction to DB2 recursive query

Source: Internet
Author: User

DB2 recursive query, also known as tree query, is a very important query method in DB2 databases. The following describes the knowledge of DB2 recursive query for your reference.

Data Structure]

Process_id par_process_id fw_id
742482939 414358129 471
414358129 1707251033 470
1707251033 null 468

DB2 recursive query parent process_id]
With par (process_id, par_process_id)
(
Select process_id, par_process_id from docm_process_ts a where fw_id = '20140901' 1]
Union all
Select child. process_id, child. par_process_id from par, docm_process_ts child where par. par_process_id = child. process_id 2]
)
Select process_id, par_process_id from par where par. par_process_id is null 3]


1] This SQL statement is initialized and only executed once. The execution result is passed to table 2 as a seed]

2) recursively retrieve data from the virtual table par and the docm_process_ts table with conditions

3] This SQL statement is the final result to be queried.
 

Implementation of DB2 Paging

DB2 cursor and usage

How to manage DB2 tablespaces

DB2 database Permissions

Quick clearing of big data DB2 tables

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.