I have a list user_id
of N
integers, e.g.
[1001, 1023, 13452, 1679834, ...]
and a table:
CREATE TABLE content (
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
user_id INT,
content VARCHAR(100),
score INT
);
I need to take those N
integers from user_id
and for each user_id
get the top 3 content
that has the highest score
. So basically I need to run this query N
times:
SELECT *
FROM content
WHERE user_id=1001
ORDER BY score DESC
LIMIT 3;
N
could be a very large number. So I'd very much want to avoid running those queries one-by-one.
Is there any way to reduce the number of queries I need to run? Some sort of bulk select perhaps?