Skip to content

Join same two tables multiple times in one query [closed]

I have problem with my query and i can not figure it how to do it. What i want to do is to display “Ban By” name to table. I know how to join two tables and that is what i did here:

SELECT reason, expired, created, actor_id, name 
FROM bm_player_ban_records 
LEFT JOIN bm_players ON bm_player_ban_records.player_id = bm_players.id 
WHERE bm_players.name = 'NexoR'

but i need to join the same tables again and now i need to pair them by actor_id to id and than display name and this is where my brain stopped and do not know how to do it. https://imgur.com/a/uW7jznk <- images

Answer

SELECT  
    reason, 
    expired, 
    created, 
    actor_id, 
    name 

FROM 
    bm_player_ban_records
  LEFT JOIN 
    bm_players AS BAN_by ON Ban_by.id = bm_player_ban_records.player_id 
  LEFT JOIN
    bm_players AS ACTORE ON ACTORE.id = bm_player_ban_records.actor_id
WHERE 
    Ban_by.name = 'NexoR'

you will likely need to prefix the fields in the SELECT with the correct alias for the table