This question is a bit vague and I do apologize, hopefully the example below will clear it up. It's a fairly elementary question, I just can't seem to quite find the right solution with my very limited knowledge and SQL relevant vocabulary
There is a table with people,
create table People (
id integer,
name LongName,
primary key (id)
);
And one for workers that references people
create table Workers (
id integer references People(id),
worktype varchar(20),
primary key (id)
);
and lastly a works_for relationship
create table Works_for (
worker integer references Workers(id),
employer integer references Job(id),
primary key (worker,job)
);
Now what I want to do is get all people that work at least 20 jobs, so I get the correct list of id's with the following query:
SELECT worker
FROM Works_for
GROUP BY worker
HAVING COUNT(worker) > 20;
However I also want to get the names of these workers. How would I go about this? I've tried a number of things but I keep running into errors. Any help would be much appreciated!