Let's say I have the following tables:
create table user (
id int
);
create table transaction (
user_id int,
date timestamp,
amount int
);
I have an array of 100 users (result from another query). I'd like to get the 100 last transactions of each user from my input array.
I've tried a simple query wrapped in a for loop in a script, but I'm thinking there must be a way to do this with a where in in pure SQL.
unnest.with t(el) as (select unnest (the_array)) select * from t cross join lateral (the_query) l;