Reputation: 2590
We have 3 tables:
1: jobs
with a single column name
2: workers
with a single column name
3: jobs_workers
lookup table with job_id
and worker_id
columns.
Now I got an array of job IDs looking like: [1,2,3]
how do I select only workers that are doing ALL 3 jobs?
Upvotes: 0
Views: 23
Reputation: 1269603
You could do:
select jw.worker_id
from job_workers jw
where jw.job_id = any @ids
group by jw.worker_id
having count(*) = array_length(@ids);
Upvotes: 1