Devender Yadav
Devender Yadav

Reputation: 23

How can I get whole row with distinct column in hibernate using hql?

Name of table-test

Id      Name      Profession
1        a         Engg
2        b         Engg
3        c         Doctor
4        d         Doctor

Desired Output:

 Id      Name      Profession
 1        a         Engg
 4        d         Doctor

I want to get rows containing unique profession as shown in the table above. I tried

hql-

"select distinct profession from test"

It's returning String profession. How can I get whole row?

Upvotes: 1

Views: 3760

Answers (1)

Gautam Savaliya
Gautam Savaliya

Reputation: 1437

DISTINCT will return only column with unique value.

Instead of :

select distinct profession from test

Use below hql query:

select * from test group by profession

Upvotes: 2

Related Questions