group by with latest record

how to achieve latest record group by.




 $query = Ledgerbillbalance::find();

        $query->select(['id','MAX(id) AS asd','name','balance','date']);

        $query->andWhere(['<','id','asd']);

        $query->groupBy(['name','guid']);

        $query->orderBy('Max(id) AS DESC');



i tried withandwhere and i tried with orderBy also,but nothing is working.

Probably the same approach can solve it.

Check the following thread.

http://www.yiiframework.com/forum/index.php/topic/69282-query-activerecord-for-unique-foreign-key-with-max-timestamp