Activity Forums Salesforce® Discussions Will Below Query Work?

  • Will Below Query Work?

    Posted by Aman on September 20, 2018 at 2:53 pm

    Will Below Query Work? Explain.
    select Count(id), Name, Address__c From Opportunity Group By Name

    • This discussion was modified 5 years, 7 months ago by  Aman.
    Parul replied 5 years, 7 months ago 3 Members · 2 Replies
  • 2 Replies
  • shariq

    Member
    September 20, 2018 at 2:57 pm

    Hi,

    Above query will throw an error.

    Explanation: In Group by clause the columns selected must be either used in Group by clause or in aggregate functions. The Name field is neither used in aggregate methods and in group by clause and hence will result in error “Malformed Query”.

    Thanks

  • Parul

    Member
    September 20, 2018 at 4:38 pm

    Adding some points

     

    The expression cannot include Aggregate Functions; however, the GROUP BY clause is often used with Aggregate Functions to return summary values for eachgroup. The GROUP BY clause without aggregates is similar to using SELECT DISTINCT. ... The GROUP BY clause does not order data.

    Thanks

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos