skip to Main Content

I have a table.
The table has several columns with user ids.
There is only one table with users.
enter image description here

If there was one column, then everything is clear, we do join user_id = users.id and then use users.name.
What if there are multiple columns? How can I do a join on each of the columns?
enter image description here

2

Answers


  1. SELECT ua.name as adduser,
           ue.name as edituser,
           ud.name as deleteuser
    FROM Table t
    JOIN Users ua on t.adduser_id = ua.id
    JOIN Users ue on t.edituser_id = ue.id
    JOIN Users ud on t.deleteuser_id = ud.id;
    
    Login or Signup to reply.
  2. You can join the same table using different aliases.

    select adduser.name as adduser,
        edituser.name as edituser, 
        deluser.name as deluser
    from table as t
    join users as adduser
        on t.adduser_id = adduser.id
    join users as edituser
        on t.edituser_id = edituser.id   
    join users as deluser
        on t.deluser_id = deluser.id
    
            
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search