0

Given these tables/fields:

people:

id
socialID
name

peopleStats:

id
socialID
drVisitsAmount
receipAmounts
operationsAmount

Im trying to get last 3 records from peopleStats (ordered by id DESC) for a given array of socialIDs (3 records per each socialID):

$dummyData = PeopleStats::find()
            ->where(['socialID' => $socialIDs])
            ->groupBy(['socialID'])
            ->orderBy(['id' => SORT_DESC])
            ->limit(3)
            ->all();

but i just get 3 records and not 3 per each. How can i get this data?

Thank you in advance,

Kamran Khatti
  • 3,754
  • 1
  • 20
  • 31
farrusete
  • 435
  • 9
  • 24
  • 1
    Use Join with "people" table to get your required result. – Husnain Aslam Nov 02 '16 at 14:42
  • Tried that but still receiving just 3 items: $dummyData = PeopleStats::find() ->where(['peopleStats.socialID' => $socialIDs]) ->joinWith('people') ->groupBy(['people.socialID']) ->orderBy(['peopleStats.id' => SORT_DESC]) ->limit(3) ->all(); – farrusete Nov 02 '16 at 19:36
  • what does your desired SQL look like? Also, there is an "->offset" method to skip items. – e-frank Nov 03 '16 at 11:51
  • use `->asArray()->all()` instead of just `->all()` this might work. – Kamran Khatti Nov 03 '16 at 16:18

0 Answers0