Assuming you have a unique ID for tbl_SongsPlayed
, you could do something like this:
// Filter the songs first
With SongsForStation
As (
Select *
From tbl_SongsPlayed
Where Station = @Station
)
// Get the songs
Select *
From SongsForStation
Where SongPlayId <> (
// Get the top song, most recently played, so you can exclude it.
Select Top 1 SongPlayId
From SongsForStation
Order By DateTimePlayed Desc
)
// Sort the rest of the songs.
Order By
DateTimePlayed desc
Where