How can Find the count of all the managers in the database
with employee and departments table
Employee Database
How can Find the count of all the managers in the database
with employee and departments table
Employee Database
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Tuhin PaulPosted Feb 9, 2025, 5:56 PM
To find the count of all distinct managers in the database, we need to identify employees who are listed as
MANAGER_IDin either theEMPLOYEEStable or theDEPARTMENTStable. Since a manager is also an employee, we can use theMANAGER_IDcolumn from both tables and join them with theEMPLOYEEStable to get the unique list of managers.We need to:
MANAGER_IDvalues from theDEPARTMENTStable.MANAGER_IDvalues from theEMPLOYEEStable.MANAGER_IDvalues using aUNIONto ensure uniqueness.MANAGER_IDvalues with theEMPLOYEEStable to retrieve the corresponding employee details.0.MANAGER_IDvalues are properly populated in bothDEPARTMENTSandEMPLOYEEStables.Muhammad Imran AnsariPosted Feb 9, 2025, 4:46 PM
suppose you need to find distinct managers from both the Employees and Departments tables. In that case, you should combine the
manager_idfrom the Employees table and themanager_idfrom the Departments table then useUNIONto merge distinctmanager_idvalues from both tables.Here is the query:This query gives the total count of unique managers across both Employees and Departments tables.
Kiran KumarPosted Feb 9, 2025, 5:43 AM
yes unique records can be found in employee table but need to find the distinct managers from employee and departments tables
so do I need to join the tables of both and filter based on departmentId or managerid matching
Muhammad Imran AnsariPosted Feb 8, 2025, 9:09 AM
As the structure diagram,
manager_idcolumn exists in theEmployeestable (indicating that each employee has a manager, except for top-level managers who haveNULL), you can find the total number of unique managers in the database using theCOUNT(DISTINCT manager_id)function.Kiran KumarPosted Feb 8, 2025, 8:23 AM
We dont have managers table the employee table and departments we need to get joining it
But here a Mnager also a employee so how can we get it
Attached structure diagram
Kiran
Dashrath HapaniPosted Feb 7, 2025, 12:11 PM
Consider two table manager and employee where manageid is FK in emaployee table.
Muhammad Imran AnsariPosted Feb 7, 2025, 11:43 AM
To find the count of all the managers in a database with Employee and Departments tables, you typically need to identify which employees are managers. This is usually done by checking if an employee's ID appears in a manager-related field in the Departments table or if there is a specific column in the Employee table that indicates whether an employee is a manager.
Assumptions:
Employee Table: Contains employee details, including employee_id, name, etc.
Departments Table: Contains department details, including department_id, department_name, and manager_id (which references the employee_id of the manager).
You can count the number of unique managers by querying the
Departmentstable and counting the distinctmanager_idvalues.Alternative Approach:
If the Employee table has a column that indicates whether an employee is a manager (e.g., is_manager), you can directly count the number of employees where is_manager is true.