Welcome Guest. Sign in or Signup

3 Answers

Aggregate functions and Group by Clause

Asked by: 1604 views SQL

You would have written some SQL statements for sure that has an aggregate function followed by some sort of group by clause. Is it always necessary for an aggregate function to have a group by clause?

Related Questions

3 Answers



  1. Ravi on Apr 05, 2013 Reply

    Yes. Group by should include all fields in select statement which are not part of non-aggregate functions.


    Warning: mysql_query(): No such file or directory in /home/psoft_adm/psoftsearch.com/interview-questions/wp-content/themes/Answers/library/includes/comment-rating.php on line 57

    Warning: mysql_query(): A link to the server could not be established in /home/psoft_adm/psoftsearch.com/interview-questions/wp-content/themes/Answers/library/includes/comment-rating.php on line 57

    Warning: mysql_query(): No such file or directory in /home/psoft_adm/psoftsearch.com/interview-questions/wp-content/themes/Answers/library/includes/comment-rating.php on line 64

    Warning: mysql_query(): A link to the server could not be established in /home/psoft_adm/psoftsearch.com/interview-questions/wp-content/themes/Answers/library/includes/comment-rating.php on line 64

    +3 Votes Thumb up 0 Votes Thumb down 0 Votes



  2. Candidate on Apr 05, 2013 Reply

    A group by is not always required.
    Say, Select count(*) from PSOPRDEFN;
    This statement doesn’t need a group by.

    However, as Ravi points out in the above answer, if you have some fields (other than the aggregate function) in the select clause, those fields should go into the group by as well.


    Warning: mysql_query(): No such file or directory in /home/psoft_adm/psoftsearch.com/interview-questions/wp-content/themes/Answers/library/includes/comment-rating.php on line 57

    Warning: mysql_query(): A link to the server could not be established in /home/psoft_adm/psoftsearch.com/interview-questions/wp-content/themes/Answers/library/includes/comment-rating.php on line 57

    Warning: mysql_query(): No such file or directory in /home/psoft_adm/psoftsearch.com/interview-questions/wp-content/themes/Answers/library/includes/comment-rating.php on line 64

    Warning: mysql_query(): A link to the server could not be established in /home/psoft_adm/psoftsearch.com/interview-questions/wp-content/themes/Answers/library/includes/comment-rating.php on line 64

    +10 Votes Thumb up 0 Votes Thumb down 0 Votes



  3. Sivasan on Apr 19, 2013 Reply

    SetSearchDialogBehavior(0);

    Use this code in Component Record SearchInit event


    Warning: mysql_query(): No such file or directory in /home/psoft_adm/psoftsearch.com/interview-questions/wp-content/themes/Answers/library/includes/comment-rating.php on line 57

    Warning: mysql_query(): A link to the server could not be established in /home/psoft_adm/psoftsearch.com/interview-questions/wp-content/themes/Answers/library/includes/comment-rating.php on line 57

    Warning: mysql_query(): No such file or directory in /home/psoft_adm/psoftsearch.com/interview-questions/wp-content/themes/Answers/library/includes/comment-rating.php on line 64

    Warning: mysql_query(): A link to the server could not be established in /home/psoft_adm/psoftsearch.com/interview-questions/wp-content/themes/Answers/library/includes/comment-rating.php on line 64

    -4 Votes Thumb up 0 Votes Thumb down 0 Votes


Answer Question