Query a twitter-to-sqlite database and find the "deepest" tweets in a reply thread, adapted from https://gist.github.com/robinhouston/f689a4b833dc027a3fd97e3de855927b

October 6, 2019 ยท View on GitHub

with recursive thread as ( select id, in_reply_to_status_id, 0 as depth from tweets where in_reply_to_status_id is null union select tweets.id, tweets.in_reply_to_status_id, 1 + thread.depth as depth from thread join tweets on tweets.in_reply_to_status_id = thread.id) select * from thread order by depth desc