I have a situation for which I am trying to find most optimized way.

I have 2 objects Obj_1 and Obj_2. Obj_2 is child of Obj_1 with MD relation.

Each record in Obj_2 is having one field with version number (Integer)

I want to find that for each Obj_1 master record the max versionnumber child Obj_2 record.

I know I can do it by iterating over for loop or by performing 2 queries, but I am thinking more from single query perspective so that I get all child Obj_2 records which are max sharing common parent record.

Thanks Ray

2 Answers 2


Can you try this.

Code Snippet

[SELECT Obj1Id, max(VersionNUmber__C) FROM Objc2 GROUP By Obj1Id]

Did you try this?

SELECT Obj_1.Id, MAX(Version) FROM Obj_2 GROUP BY Obj_1.Id

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .