Home > Net >  Set column values of a table based on another table in mysql
Set column values of a table based on another table in mysql

Time:01-01

I have two tables: Employees and Pharmacies.

In table Employees I have a column name Pharmacy which tells me what pharmacy an employee works at, and also a column with the names of the employees.

In table Pharmacies I have a column of pharmacies and I want to add a new one named Number_of_employees which to contain the number employees from the corresponding pharmacy where he works.

Any ideas how to do this ?

CodePudding user response:

DON'T ADD the column Number_of_employees

you can return Number_of_employees value by query

Select Pharmacies.*, count(Employees.Pharmacy) as Number_of_employees from Pharmacies
     join Employees on Pharmacies.id = Employees.Pharmacy
group by Employees.Pharmacy
  • Related