I was wondering if this is possible to make MySQL do a “double search”; I don’t really know how to say it well so here’s an example:
I have a table of songs information (title,album, etc etc …). I want to get the next song in the album. I have the ID of the current song. Currently I get the row, check the album and track field, then do another MySQL query based on album field and check if there is another track after the current one.
Could I, in one query, tell MySQL that I want all rows of the album contained in the row of the id I have?
Since I really don’t know if this is possible or how to describe it, I didn’t find anything useful on Stack Overflow, so sorry if there is already something similar.
You could use a JOIN to get what you want. Assuming your table has an ID that links to an album something like this would work to get everything that comes after the track currently being listened to.
Obviously, if you want everything in the album then remove the second condition. If you want to include the track being listened to change
>to>=.You’ve just commented:
If this is the case then then
b.song_id > a.song_idis probably incorrect. You haven’t given us your full schema but I would highly recommend if yoursongstable contained the order the tracks should be played in, so it would look something like(SONG_ID, ALBUM_ID, ALBUM_ORDER, ... more song level info ). Your query would then become: