JPQL / SQL: How to select * from a table with group by on a single column?
- by DavidD
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.