I think it is possible in sqlite using a subquery, might be interesting to experiment with it