• #39223
    Forcetalks

    How to write the “where” Clause In Soql when group by is used?

    How to write the “where” Clause In Soql when group by is used?

    #39232
    Salesforce | Sagar Sagar #76
    Forcetalks

    The following query should work, for example:

    SELECT
    Description, DAY_ONLY(CreatedDate), count(Id),
    MIN(LastModifiedDate), MAX(LastModifiedDate),
    MIN(ActivityDate), MAX(ActivityDate),
    COUNT_DISTINCT(WhatId)
    FROM Task
    WHERE WhoId = :contactId
    GROUP BY Description, DAY_ONLY(CreatedDate)

    If you really need values from the other fields, you should question why you are grouping in the first place. If you want to include them in your SELECT clause, you need to either GROUP BY them as well or decide on the proper aggregation method to apply to them.

    #39241
    Forcetalks

    Suggest You to use “HAVING” clause, when you are using GROUP BY –

    Syntax – SELECT LeadSource, COUNT(Name)
    FROM Lead
    GROUP BY LeadSource
    HAVING COUNT(Name) > 100

    Thanks.

    #41458
    Forcetalks

    Hello,

    We using HAVING clause insted of WHERE clause in GROUP BY

    Thanks.

Viewing 4 posts - 1 through 4 (of 4 total)

Please to reply to this topic.

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2019 Forcetalks. All Right Reserved.

Log in with your credentials

or    

Forgot your details?