+ Start a Discussion

DB query for selective records.

Hi All,


Is it possible to get the top 3 records from a custom object using a query for e.g. i have 5 records for todays date (14 Mar) and 4 records for tomorrow (15 Mar) and so on. What I need here is to get the top 3 records for each day.




try using 'order by createddate desc'  to get the top most records

Imran MohammedImran Mohammed

As Shruti said, fetch the records using order by created date desc and iterate over the list to find the top 3 records for each day.


example of what Imran is saying:


Select Id, Name from Custom_Object__c Order By CreatedDate Desc limit 3


This should work.