Run Code
|
Code Wall
|
Users
|
Misc
|
Feedback
|
About
|
Login
|
Theme
|
Privacy
SQL hierarchical query. branch of responses.
with recursive messages as ( select 1 as id, 1 as uid, 'a' as m, null as to_id union all select 2 as id, 1 as uid, 'b' as m, 1 as to_id union all select 3 as id, 1 as uid, 'c' as m, null as to_id union all select 4 as id, 1 as uid, 'd' as m, 1 as to_id union all select 5 as id, 1 as uid, 'e' as m, 2 as to_id union all select 6 as id, 1 as uid, 'f' as m, 1 as to_id union all select 7 as id, 1 as uid, 'g' as m, 2 as to_id ), q0 as ( select * from messages where m = 'a' ), q1(tid, msg, lvl) as ( select id, m, 0 from q0 union all select id, m, lvl + 1 from messages inner join q1 on to_id = tid ) select * from q1
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
test
How i can get the difference of closest two date in two table join in postgresql
nested array to table
Pedido_Insert_Into
univesp
fgf
SQL primes, sqrt sieve
Professional Networking Social Media Website SQL Analysis
arjun
find null in any column of table using PostgreSQL
Please log in to post a comment.