parent
b85fa26c6a
commit
ce24c1483e
@ -1,15 +1,15 @@
|
|||||||
```sql
|
```sql
|
||||||
WITH RECURSIVE hierarcy (id, title, description, parent_id) AS
|
WITH RECURSIVE child (id, title, description, parent_id) AS
|
||||||
(
|
(
|
||||||
SELECT id, title, description, parent_id
|
SELECT id, title, description, parent_id
|
||||||
FROM items
|
FROM items
|
||||||
WHERE id = 38
|
WHERE id = 38
|
||||||
UNION ALL
|
UNION
|
||||||
SELECT items.id, items.title, items.description, items.parent_id
|
SELECT parent.id, parent.title, parent.description, parent.parent_id
|
||||||
FROM hierarcy JOIN items
|
FROM child JOIN items as parent
|
||||||
ON hierarcy.parent_id = items.id
|
ON child.parent_id = parent.id
|
||||||
)
|
)
|
||||||
SELECT * FROM hierarcy;
|
SELECT * FROM child;
|
||||||
```
|
```
|
||||||
|
|
||||||
https://www.mysqltutorial.org/mysql-adjacency-list-tree/
|
https://www.mysqltutorial.org/mysql-adjacency-list-tree/
|
||||||
Loading…
Reference in new issue