mysql - Select data from one table which is connected to another 2 tables -


i have 3 tables: emplyees, jobs , departments

enter image description here

what i'm trying achieve number of emplyees 1 department.

i tried something:

select count(emplyees.id) emplyees  inner join job on (job.id = emplyees.job_id)  inner join department on (department.id = 2) 

but returns number of emplyees departments. advice please?

an exists clause allow limit existence of without having worry whether or not employee has other jobs, keep count easy figure.

also, since thing need department id, can leave table out , filter dept_id field of job table.

 select count(id)    employees   exists (         select      1                job               id = employees.job_id             ,     dept_id = 2      ) 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -