function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
LaaralLaaral 

How to query only the latest data

I'm trying to make a query which fetches the latest(one) data per setup. I've made it this far with the query
So the problem is I should fetch the latest recurring fee data from setup, but can't understand should I use Group by or order by to fetch from every setup the latest recurring fee data.

Select id, name, date_of_invoice__c, setup__c from recurring_fee__c where
setup__c in (select id from Setup__c where RecordType.name IN( 'infra','hardware' )
and cost_center__r.groupid__c = '0012000000AK643' ) ORDER BY setup__c desc
SwaroopaSwaroopa
Hi Aral,

To get the latest data you need to use Order by. If you want to get the latest data based on more than 1 column then you need to use group by followed by order by