I am making a music player where we have stations. I have a table called histories. It has data on the songs a user likes, dislikes or skipped. We store all the times that a person has liked a song or disliked it. We want to get a current snapshot of all the songs the user has either liked (event_type=1) or disliked (event_type=2) in a given station.
The table has the following rows:
id
(PK int autoincrement)station_id
(FK int)song_id
(FK int)event_type
(int, either 1, 2, or 3)
Here is my query:
SELECT song_id, event_type, id
FROM histories
WHERE id IN (SELECT MAX(id) AS id
FROM histories
WHERE station_id = 187
AND (event_type=1 OR event_type=2)
GROUP BY station_id, song_id)
ORDER BY id;
Is there a way to make this query run without the inner select? I am pretty sure this will run a lot faster without it