JPQL / SQL: How to select * from a table with group by on a single column?
Posted
by DavidD
on Stack Overflow
See other posts from Stack Overflow
or by DavidD
Published on 2010-04-27T18:04:27Z
Indexed on
2010/04/27
18:13 UTC
Read the original article
Hit count: 612
I would like to select every column of a table, but want to have distinct values on a single attribute of my rows (City in the example). I don't want extra columns like counts or anything, just a limited number of results, and it seems like it is not possible to directly LIMIT results in a JPQL query.
Original table:
ID | Name | City
---------------------------
1 | John | NY
2 | Maria | LA
3 | John | LA
4 | Albert | NY
Wanted result, if I do the distinct on the City:
ID | Name | City
---------------------------
1 | John | NY
2 | Maria | LA
What is the best way to do that? Thank you for your help.
© Stack Overflow or respective owner