tags:

views:

48

answers:

2

Hi, I have two object : "Mother" and "Child". Mother have many Children, How can i get from the DB a Mother with only 2 Children (or less), the younger and the older. Thanks

edit:

The mother i want to get have a lot of children but i only want the younger and the older.

Something like that :

from Mother m left join m.Child c where (max(c.age) or min(c.age))

A: 
FROM Mother m WHERE count(m.Children) <= 2
David Pfeffer
A: 

I founded this and it works :

from M as m    
left join m.C as c
where m.Id = :idM
and
(c.Age = (select min(c.Age) from C c where c.M.Id = :idM)
or
c.Age = (select max(c.Age) from C c where c.M.Id = :idM))
order by c.Age
Julien