2

how i can access unique day my Soql is

select Id, Date__c from Object__c where ORDER BY Date__c DESC

this Soql is giving me data as

2013-08-17 04:59:06
2013-08-13 04:59:06
2013-08-13 04:59:06
2013-08-12 04:59:06
2013-08-10 04:59:06
2013-08-10 04:59:06

But i want only day wise i.e

2013-08-17 04:59:06
2013-08-13 04:59:06
2013-08-12 04:59:06
2013-08-10 04:59:06

How i can do this.

  • 1
    You don't care about the objects themselves, just the unique dates for which there is at least one occurrence in the database? – Doug B Aug 22 '13 at 10:43
  • Ya just unique date.. – Jayant Jadhav Aug 22 '13 at 10:46
3

Use an aggregate query like this:

select day_only(createdDate)
from account
group by day_only(createdDate)
order by day_only(createdDate)

This returns one row for each date that has an account created on it. You can apply this to your own object and add whatever where conditions are relevant. Note that the result will be a list of AggregateResult and not a list of account or object__c.

Refer also to http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_SOQL_agg_fns.htm

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.