MYSQL: How to JOIN two tables on the same query referencing the same table twice

前端 未结 3 1633
心在旅途
心在旅途 2021-01-26 05:40

I have two tables. I\'m trying to JOIN the sample two tables below with table 1 referencing Table 2 twice. For example if I look at Table 1: Group 2 and Members 7, it should loo

3条回答
  •  天涯浪人
    2021-01-26 06:11

    Join with Table 2 twice on different columns.

    SELECT t1.*, t2.name AS group_name, t3.name AS member_name
    FROM Table1 AS t1
    JOIN Table2 AS t2 ON t1.group = t2.id
    JOIN Table2 AS t3 ON t1.members = t3.id
    

提交回复
热议问题