SQL Group by Clause With Examples

Group by Clause

The WHERE clause is a filter that defines the conditions each row in the source tables must meet to qualify for the SELECT.

We use the SQL WHERE clause when we require to fetch the data from single or multiple tables. If the condition is specified then it will return a specific value. We can also use the WHERE clause with the UPDATE, DELETE SQL statement

Syntax:

 SELECT column  
 FROM table_name  
 WHERE conditions   
 GROUP BY column  
 ORDER BY column

Sample Table:

PRODUCT COMPANY QTY RATE COST
Item1 Com1 2 10 20
Item2 Com2 3 25 75
Item3 Com1 2 30 60
Item4 Com3 5 10 50
Item5 Com2 2 20 40
Item6 Cpm1 3 25 75
Item7 Com1 5 30 150
Item8 Com1 3 10 30
Item9 Com2 2 25 50
Item10 Com3 4 30 120

 SELECT COMPANY, COUNT(*)  
 FROM PRODUCT_MAST   
 GROUP BY COMPANY;

Result:

Com1   5
Com2   3
Com3   2

Read Also: