我在表A中有两个表,使用表B作为参考。我尝试使用内连接,但只得到一个列结果。 例如。
Table A
Reciever | Sender
1 | 2
1 | 3
Table B
id | Name | Lastname
1 | James | Todd
2 | Jimmy | Jones
3 | Tom | Brown
Desired result from joining the tables would be
Table A
Reciever | Sender
James Todd | Jimmy Jones
James Todd | Tom Brown
答案 0 :(得分:2)
SELECT
CONCAT(t1.Name, ' ', t1.Lastname) As Reciever,
CONCAT(t2.Name, ' ', t2.Lastname) As Sender
FROM
TableA INNER JOIN TableB t1 ON TableA.Reciever=t1.id
INNER JOIN TableB t2 ON TableA.Sender=t2.id
请参阅小提琴here。