I'm working on two tables called Students
and departments
Students
StudentId | Name | Address | DepartmentId
1 | Simons | Los Angeles| 001
2 | Mark | Texas | 001
3 | Kelly | Florida | 002
4 | Philip | New York | 002
Department
DepartmentId | Name | Date_Creation
001 | Maths | 01/09/2021
002 | Physics | 01/08/2021
What I need exactly is to retrieve all information from Department Table with the number of students that are from the department ( group by ).
Expected results:
DepartmentId | Name | NumberOfStudents
001 | Maths | 2
002 | Physics | 2
I have tried to execute the query but it did not give me any result:
Select DepartmentId, Name, (select count(*)
from Students s, Departments d
where s.DepartmentId = d.DepartmentId) as NumberOfStudents
What can I modify to get the needed result?