I have a person
table that stores the names of people:
personid firstname lastname
526 Joe Burnaby
527 Andy Brandt
528 Ben Oxfold
These persons are stored in customer
and employee
tables
customerid personid
745 526
746 527
employeeid personid
628 528
Then there is a training
table that stores each column as so
trainingid trainerid customerid rating
900 628 745 4
901 628 751 2
How can I write a Select that displays both names? The expected output should be
Trainer Customer Rating
Ben Oxfold Joe Burnaby 4
Ben Oxfold Andy Brandt 2
I'm not sure how to go about writing a Select for this, as I bump into a wall in the columns I select:
SELECT
person.firstname||person.lastname AS "Trainer",
person.firstname||person.lastname AS "Customer",
rating
FROM training
JOIN employee ON training.trainerid=employee.employeeid
JOIN customer ON training.customerid=customer.customerid
JOIN person ON employee.personid=person.personid
JOIN person ON customer.personid=person.personid;
I tried this, but obviously it will only display whoever you join first in both rows.