TechnoLearnAcademy

SQL GROUP BY WITH JOIN

THE SQL GROUP BY Statement is used to group rows that have the same values in specified columns into summary rows.
We can apply aggregate functions like SUM, COUNT, AVG, MAX, or MIN to calculate values for each group.
GROUP BY WITH JOINS.
Let’s understand the group by statement with joins with an example. For demonstration purposes, we will be using the table emp and table project.
         Table Emp
Table Project

Example:

   Objective: In this example, we will count the number of projects in each department.
                     SELECT e.Department , COUNT(p.Project) as [ProjectCount] FROM Tbl_Emp as e
                                                        INNER JOIN Tbl_Project as p
                                                        on e.Ecode = p.Ecode                                                                                                                                                                         GROUP BY e.Department;
    Output:
Note: We can use Max, Min, and Avg functions to find the Max, Min, and Avg values of each department.
Scroll to Top