Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Join only first row with HQL

Is it possible to join only first row (or just any other row but only one) using hql?

select 
 config.id, mg.modelGroupName, min(deliveryType.id) 
from 
 NotificationConfig config, NotificationConfigEntry configEntry, SettlementModelGroup mg 
join 
 configEntry.notificationConfigEntryPK.user user 
join 
 configEntry.notificationConfigEntryPK.deliveryType deliveryType 
join 
 config.notificationType notifType 
join 
 notifType.objectType objectType 
where 
 config.id = configEntry.notificationConfigEntryPK.notificationConfig.id 
 and ( mg.modelId = config.objectId or config.objectId is null )

This is the code i'm having right now, of course

min(deliveryType.id) 

doesn't work. Relation between mg.modelId and config.objectId is not mapped, and deliveryType is a list. I can't use distinct cause I need to be able to order by deliveryType (this won't make any sense, but i need to make it anyway) and modelGroupName.

like image 732
Tuan Pham Avatar asked Aug 08 '13 16:08

Tuan Pham


1 Answers

select 
 config.id, mg.modelGroupName, deliveryType.id 
from 
 NotificationConfig config, NotificationConfigEntry configEntry, SettlementModelGroup mg 
join 
 configEntry.notificationConfigEntryPK.user user 
join 
 configEntry.notificationConfigEntryPK.deliveryType deliveryType with deliveryType.id = (select min(id) from configEntry.notificationConfigEntryPK.deliveryType)
... 
like image 68
Alex Avatar answered Sep 20 '22 06:09

Alex