I have a table with two foreign keys in one table.
Table PROJECTS
- Id
- Owner - FK
- Client - FK
and
table USERS
- Id
- Name
I'd like to select all projects with appropriate names of the owner and client
The result should look like:
Id | OwnerName | ClientName
You just need two joins to that table.
SELECT p.Id,
u1.Name OwnerName,
u2.Name ClientName
FROM Projects p
LEFT JOIN
Users u1
ON p.Owner = u1.Id
LEFT JOIN
Users u2
ON p.Client = u2.Id
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With