One of the tasks I needed to complete for my Podcast application was showing in the Podcast view the next and previous podcasts from the same show. I mean, we can’t just tell this to the database and expect the engine to just know what we’re trying to do. In other words, there is no query we can do to retrieve what comes next and what comes before a given record, because SQL doesn’t know what are valid “neighbor” records, less about how to order them natively since the last varies from engine to engine.
Instead of forcing our way inside raw SQL calls to the database and complex queries just for the sake of doing everything in one line, we will just issue two queries more: one for the next record, and other for the previous record.
Let’s say, for example, we use UUID and we want to filter Podcasts by their show UUID.