You need to sign in to do that
Don't have an account?
Vinay J
Aggregate child records in lookup
Auction and Bid are objects in lookup where bid is child. For a given auction, I want to find out record id of Bid record with maximum bid amount. Can it be done with aggregate functions? I'm getting correct result when I execute the below mentioned query, but I'm unable to get the record id of bid record.
Select max(Bid_Amount__c) from Bid__c where auction__c='a0617000000MQzm'
Select max(Bid_Amount__c) from Bid__c where auction__c='a0617000000MQzm'
Select id,max(Amount__c) from Bid__c group by id,auction__c having auction__c='a0q90000005JRF9' order by Max(amount__c) desc limit 1
Please mark this as the best answer if it resolved your issue.
All Answers
You haven't query id.
Select id, max(Bid_Amount__c) from Bid__c where auction__c='a0617000000MQzm'
select id, max(Bid_Amount__c) from Bid__c where auction__c='a0617000000MQzm' groupby auction__c
Select id,max(Amount__c) from Bid__c group by id,auction__c having auction__c='a0q90000005JRF9' order by Max(amount__c) desc limit 1
Please mark this as the best answer if it resolved your issue.
Select Auction__c,max(Amount__c) from Bid__c group by auction__c order by Max(amount__c) desc
On auction, I'm populating amount and owner's name of highest bid. Right now, I'm doing it through trigger, by fetching all bids associated to auction (SELECT id, Name, Bid_Amount__c, High_Bidder__c, (SELECT ID, Name, Bid_Amount__c, Owner.id FROM Bids__r) FROM Auction__c) and then parsing through them to decide highest bidder. I want to use aggregate finction to achieve the same. Please suggest if you can think on any workaround.