Reputation: 3998
im looking for query to load and group the data
i do have 1:n relationship of Parent:Child
and i want to pull latest child,instead of children, of a parent
that means each entry should have unique parent with latest child.
Child Table
Desired Results
Tried:
i have tried following query but it get me oldest results
SELECT c.* FROM child AS c GROUP BY c.parent_id HAVING(MAX(c.order))
Thanks in advance
Upvotes: 3
Views: 105
Reputation: 135918
select ct.*
from ChildTable ct
inner join (select parent_id, max(order) as MaxOrder
from ChildTable
group by parent_id) q
on ct.parent_id = q.parent_id
and ct.order= q.MaxOrder
Upvotes: 1