Optimizing query with joins and criteria on the last table
Context: I have an entity
users , events, and the many-to-many join table usersEvents.Goal: Given a user, I want to see its upcoming next 5 events (date sorted).
What I have done so far:
Problem:
This is not optimized given I retrieve/scan all the future events of my user => Bandwidth consumption increase. I just would like to take the 5 next ones happening in the future.
If someone could help me/give me some light to optimize this query. Thanks in advance
