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

前端 未结 3 1606
心在旅途
心在旅途 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:14

    Hard to tell exactly what you need from that description but aliasing the tables may be what you need. It works like this:

    SELECT t1.x, t2_1.y, t2_2.z
    FROM table1 AS t1
    JOIN table2 AS t2_1 ON t1.whatever = t2_1.whatever
    JOIN table2 AS t2_2 ON t1.whatever = t2_2.whatever
    ...
    

提交回复
热议问题