Grouping data

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

Pattern:

SELECT column_name FROM table_name GROUP BY column_name;
or
SELECT column_name1,column_name2 FROM table_name GROUP BY column_name1,column_name2;

Example:

Query to show only department name:

SELECT Department FROM employees GROUP BY Department;

Query to show department and designation name:

SELECT Department,Designation FROM employees GROUP BY Department,Designation;
about author

admin

salmansrabon@gmail.com

If you like my post or If you have any queries, do not hesitate to leave a comment.

Leave a Reply

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