I have a problem getting this JPA query to work on MS SQL Server 2008.
The background is as follows: Users create jobs for clients, of which there are many. I am displaying a list of his most recently used clients to the user to make the selection easier.
SELECT DISTINCT c FROM Client c
JOIN c.jobs j
WHERE j.user = ?1
ORDER BY j.created DESC
The query works just fine - using MySQL. MS SQL Server (2008) complains that I cannot sort by j.created
because it is not part of the select list. This is the error message:
ORDER BY items must appear in the select list if SELECT DISTINCT is specified.
I can't seem to find an elegant workaround for this limitation. Does anyone have an idea?