To add to what Keith says, assuming you meant ? to be a list of streams then the following would work select stream, (select max(id) from events where stream=list.stream) from list; You could form the list as a temporary table or a carray https://sqlite.org/carray.html#overview