mysql连接查询double

时间:2013-09-19 16:40:09

标签: mysql join double

表格在这里:

enter image description here

我想写;

匹配1:jonathan vs jenny,

匹配2:sam vs ruby​​,

匹配3:arif vs pamee


我尝试了很多查询但未能完成。

SELECT table1.boy_id, table1.girl_id, table1.ID, table2.id, table2.name, table2.score
FROM table1
INNER JOIN table2

1 个答案:

答案 0 :(得分:2)

SELECT  a.ID,
        b.name BoyName,
        c.name GirlName
FROM    table1 a
        INNER JOIN table2 b
            On a.boy_id = b.id
        INNER JOIN table2 c
            ON a.girl_id = c.id

您需要在table2上加入table1两次,因为table1中有两列引用了table2