codescracker


sql

SQL Group By



« Previous Tutorial Next Tutorial »


SQL GROUP BY clause is used in collaboration with SQL SELECT statement just to arrange the identical data into groups. The SQL GROUP BY clause follows the SQL WHERE clause in a SQL SELECT statement and then precedes the SQL ORDER BY clause.

Here is the general form of the GROUP BY clause in SQL:

SELECT column1, column2
FROM table_name
WHERE [ conditions ]
GROUP BY column1, column2
ORDER BY column1, column2

SQL GROUP BY Keyword Example

Here is an example of GROUP BY keyword in SQL. Consider the table CUSTOMERS having the following records:

sql group by keyword

Now, if you want to know the total amount of salary on each customer, then here is the SQL GROUP BY query:

SELECT NAME, SUM(SALARY) FROM CUSTOMERS
GROUP BY NAME;

After querying the above, you will get this output:

sql group by

« Previous Tutorial Next Tutorial »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test