mysql复杂多表连接

brccelvz  于 2021-06-23  发布在  Mysql
关注(0)|答案(1)|浏览(278)

我有三张table

Table 1       Table 2                 Table 3
id   deg       id  t1_id   name       id  t2_id  t1_id   name
101  ABC       1   202   Test 1        1   3      202    Job a
202  PQR       2   202   Test 2        2   1      101    Job b
303  XYZ       3   101   Test 3        3   2      303    job C

How write a single MySql query so that i can achieve results as Follows:

t1_name  t1_deg  t2_name t2_deg 
Test 1    PQR     Job b   ABC
Test 2    PQR     Job c   XYZ
Test 3    ABC     Job a   PQR

Thanks For Help
bjp0bcyl

bjp0bcyl1#

SELECT
    Table2.name,
    Table1.deg,
    Table3.name
FROM
    Table1
JOIN 
    Table2 ON Table2.t1_id = Table1.id
JOIN 
    Table3 ON Table1.id = Table3.t1_id;

相关问题