Trying to count number of foreign keys
Posted on 2005-05-01
I have a table with Hospitals and I need to display # number of people assigned as I display a listing of these hospitals.
I tried to redo the query but I need to figure out how to write the sum( ProviderID's ) that match to each of the hospital rows. I know the query below kind of works, but it isn't summing them together.
SELECT Hospital.HospitalID, Hospital.HospitalName, Provider.HospitalID, Provider.ProviderID
FROM Hospital INNER JOIN
Provider ON Hospital.HospitalID = Provider.HospitalID
Heres what I need to display:
ID | HospitalName | # Providers
1 Hosp A 29
2 Hosp B 0
3 Hosp C 4