MySQL Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
Mysql Tutorial
Introduction
How to Install
Database
Datatypes
Tables
INSERT
SELECT
UPDATE
DELETE
Operators
Functions
Ask Your Doubts
Feedback
 





MySQL Group By Clause


Tutorials Mysql

Topic
How to select the columns using Group by clause?


Explanation


Group By Statement:

    The MySQL Group by clause is used to display the rows and columns grouped by selective columns. It can be used to perform the aggregate functions, such as count().

    The following example query will list the name of the student and also count the repeative names using Group By Statement.

mysql> select name, count(name) from student group by name;
+-------+-------------+
| name  | count(name) |
+-------+-------------+
| anne  |           2 |
| david |           1 |
| jack  |           1 |
| mille |           1 |
| steve |           2 |
+-------+-------------+
5 rows in set (0.03 sec)
    The below query will display the name and sum of marks of the student using MySQL group by clause.
mysql> select name,sum(marks),count(*) from students group by name;
+----------+------------+----------+
| name     | sum(marks) | count(*) |
+----------+------------+----------+
| anne     |        175 |        2 |
| maichael |         82 |        1 |
| mike     |        182 |        2 |
| rock     |        100 |        1 |
| steve    |        175 |        2 |
+----------+------------+----------+
5 rows in set (0.00 sec)
    The above examples shows how to use the MySQL Group by clause in the select statement.



A Note

MySQL is the most popular open source Relational database Management system (RDBMS). Being a open source anyone can use and change the software for their needs. Hope you enjoy this tutorial. We welcome your Valuable feedbacks or suggestions on this MySQL tutorial. This is a copyright content.


Other Links

web hosting