orm - JPQL / SQL: How to select * from a table with group by on a single column? -
i select every column of table, want have distinct values on single attribute of rows (city in example). don't want columns counts or anything, limited number of results, , seems not possible directly limit results in jpql query.
original table:
id | name | city --------------------------- 1 | john | ny 2 | maria | la 3 | john | la 4 | albert | ny
wanted result, if distinct on city:
id | name | city --------------------------- 1 | john | ny 2 | maria | la
what best way that? thank help.
in jpql, this:
select e myentity e e.id in (select min(e.id) myentity e group e.city)
this returns:
myentity [id=1, name=john, city=ny] myentity [id=2, name=maria, city=la]
Comments
Post a Comment