Home > database >  For a complex SQL
For a complex SQL

Time:10-02

There is a table with the parent and child two fields, know a value of the parent field, how to write a SQL, you can query all the children of the parent and children's children?

CodePudding user response:

Write a function,
This is my post - http://bbs.csdn.net/topics/392169277, now is a little small problems,

CodePudding user response:

The parent, child, the child of the child, three level league?

CodePudding user response:

Can write their own functions? A recursive function, if there is a child, as the parent id to query

CodePudding user response:

Using a recursive common table expression

AS WITH XXX (
.
Union all
.
) select * from XXX.

This kind of structure

CodePudding user response:

A recursive query tree to baidu check

CodePudding user response:

Recursive query 4 #
  •  Tags:  
  • DB2
  • Related