If you have relevant indexes then you can do a NOT EXISTS correlated query to ensure that the record is the latest for that particular user, app. If you don't have relevant indexes and will have to do full table scans then research use of analytic functions particular to your database. All other approaches will be non-scalable or are less performant.