Home » SQL Basics » Retrieving Data » Using GROUP BY

Using GROUP BY

Using GROUP BY

Syntax: Select “column_name1″, “column_name2″,….”column_nameZ” FROM “table_name” Group by “Column_name” [asc|desc]

Example: Example: SELECT name, age FROM employee group by name, age

In the above example it displays all employees grouped by thier name and age.
Note: Group by list should contain all columns in the Select List except ones which are used in Arthemitic functions like Sum.

Example2: SELECT store_name, SUM(Sales) FROM Store_Sales GROUP BY store_name

Leave a Reply

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