Mark Evans
Mark Evans

Reputation: 81

SQL Join with Multiple User IDs

I have a table with each row containing two user ids. There is a user id for the person who created the post and a user id for the person who last edited the post.

I want to join the each user id to a user table in order to pull in the name of each person. I can do that. However, how do I return the name of each person separately?

I would like the "Created Name" and "Edited Name". Each drawing from the user table.

Thank you

Upvotes: 1

Views: 2101

Answers (1)

The Impaler
The Impaler

Reputation: 48780

Two joins should do the work:

select
  p.*,
  c.name as creator_name,
  e.name as editor_name
from post p
join user c on p.creator_id = c.id
join user e on p.editor_id = e.id

Upvotes: 2

Related Questions