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.
2
Answers
You can use a window function:
But if that array is the result of another query, then there is no need for the array to begin with.