select l.name, i.name from list as l
inner join list_items as li on li.list_id = l.id
inner join items as i on i.id = li.item_id
where items.completed = true
Imagine it's like a collaborative bookmarking app.Your options are basically:
1. Polling - re-run query periodically
2. Monitor changes to tables using triggers or CDC
-- 2a. Re-run entire query when any table is modified with DML and diff against previous result
-- 2b. Only re-run query if the changes would effect the result (e.g. if we add an `item` with `item.completed = false` then we know that our above query will never need updating.)
-- 2c. Do an efficient diff using some relational algebra magic. See Postgres IVM link I posted.
I posted the same example [here][1] with some more details.
[1]: https://math.stackexchange.com/questions/4112326/how-can-i-u...