melculetz
melculetz

Reputation: 1971

HQL Query using group by

I have the following class structure FlowerDAO with the fields (mapped using Hibernate):

I have tried this, but it doesn't work

from FlowerDAO as f where f.unitPrice<= (select min(f2.unitPrice) from FlowerDAO as f2 where f2.color=f.color)
group by f.color

Upvotes: 0

Views: 5880

Answers (1)

Kothar
Kothar

Reputation: 6629

I suspect the problem is comparing a single value to a set of results. Try replacing the <= with an 'in', so your query will read:

from FlowerDAO as f 
  where f.unitPrice in 
    (select min(f2.unitPrice) from FlowerDAO as f2 where f2.color=f.color)

Also, I've removed the 'group by' from the end, since that will only provide one result for each colour, and you mention in the question flower(s). You may want to use

order by f.color

instead?

Upvotes: 2

Related Questions