What are the alternatives to using an ORDER BY in a Subquery in the JPA Criteria API?
问题 Consider the following two tables: Project ( id, project_name) Status ( id, id_project, status_name) Where Status contains all statuses in which a Project has been. Lets say we want to query all projects for which the latest status has the name "new". The Sql query that I come up with is: SELECT q.id_project FROM status q WHERE q.status_name like 'new' AND q.id IN ( SELECT TOP 1 sq.id from status sq WHERE q.id_project = sq.id_project ORDER BY sq.id DESC ) I'm trying to replicate the above