• SQL GROUP BY – SQL Tutorial | Software Testing Material

    SQL Group By:

    The SQL GROUP BY statement is often used with aggregate functions (COUNT, MAX, MIN, SUM, AVG) to group the result-set by one or more columns.

    Syntax:

    Example:

    To fetch the total amount of salary on each Employee, then GROUP BY query would be as follows:

    Here I have executed both the queries to show you the output of SAMPLETABLE and the output of SAMPLETABLE with GROUP BY statement.

    SQL Group By

    Now, I have modified the data in the SAMPLETABLE. I have added some duplicate records.

    Again I am executing both the queries to show you the output of SAMPLETABLE and the output of SAMPLETABLE with GROUP BY statement.

    How to Insert Data in the SQL Table

    In the below image, we could see two queries. You could find duplicate values in the table name SAMPLETABLE. Total number of records are 4 based on GROUP BY in the second SELECT query. SELECT GROUP BY statement displays two columns (such as EmpName and SALARY) and grouped the records with the EmpName column.

    SQL Group By

    In the next tutorial, we will see how to use HAVING in SQL

    Check out the complete SQL Tutorial by clicking on below link:

    SQL Tutorial – Complete

    Sharing is caring.

    Share on facebook
    Facebook
    Share on twitter
    Twitter
    Share on linkedin
    LinkedIn

    Like This Post?

    We have a lot more where that came from?

    We only send really good stuff occasionally, promise.

    Rajkumar SM

    Leave a Comment

    Your email address will not be published. Required fields are marked *

    Share on facebook
    Share on google
    Share on twitter
    Share on linkedin
    Share on whatsapp

    Recent Posts:

    Scroll to Top
    API Testing eBook

    DOWNLOAD FOR FREE