I guess this query is a little basic and I should know more about SQL but haven’t done much with joins yet which I guess is the solution here.
What I have is a table of people and a table of job roles they hold. A person can have multiple jobs and I wish to have one set of results with a row per person containing their details and their job roles.
Two example tables (people and job_roles) are below so you can understand the question easier.
People
id | name | email_address | phone_number 1 | paul | paul@example.com | 123456 2 | bob | bob@example.com | 567891 3 | bart | bart@example.com | 987561
job_roles
id | person_id | job_title | department 1 | 1 | secretary | hr 2 | 1 | assistant | media 3 | 2 | manager | IT 4 | 3 | finance clerk | finance 4 | 3 | manager | IT
so that I can output each person and their roles like such
Name: paul Email Address: paul@example.com Phone: 123456 Job Roles: Secretary for HR department Assistant for media department _______ Name: bob Email address: bob@example.com Phone: 567891 Job roles: Manager for IT department
So how would I get each persons information (from the people table) along with their job details (from the job_roles table) to output like the example above. I guess it would be some kind of way of merging their jobs and their relevant departments into a jobs column that can be split up for output, but maybe there is a better way and what would the sql look like?
Thanks
Paul
PS it would be a mySQL database if that makes any difference
RE:
You can get fairly close with