ok I've run into another problem that i could have solved using join subselects in from clause in sql but for the life of me i cant figure out how to do this in hql.
This is a much better representation of what i was trying to do earlier in the thread.
I have 2 tables linked by a many-many relationship through another table.
Table1:Callrate
Table2:Prefix
Table3:Callrateprefix
Now when i reverse engineer these three tables in hibernate it creates pojo etc for only callrate and prefix and a relationship Set for eachother. (i hope im making sense my hibernate/db lingo is very immature).
It's a quite simple relationship between callrate and prefix. Every prefix has many callrates. (and for a different purpose callrates can also have many prefixes but this isnt important in this case)
So what i am trying to do is get the cheapest rate for every prefix and some rate details also.
To get the cheapest rate for every prefix i use:
Code:
select pr2.prefixid, min(cr2.rate)
from Callrate cr2 join cr2.prefixes pr2
group by pr2.prefixid
But i cant get any other callrate info along with the result like callratename etc. because ill have to put it in the group by clause and that just screws up the result.
I tried and tried and researched and tried some more (and screamed WHYYY OH WHYYY are there no join subselects!) and the best thing i could come up with was:
Code:
select pr.prefixid, cr.callrateid,cr.name,(select min(cr2.rate)
from Callrate cr2 join cr2.prefixes pr2
where cr2=cr and pr2=pr
group by pr2.prefixid)
from Prefix pr join pr.callrates cr
Which works when theres no joins but for some reason just returns the full list of rateid/prefixid matchs and there rate. I would love to know how to solve this because it will solve a bunch of other problems like this that im having to do weird things to solve. Thanks in advance :)