1

我有 2 个表,表 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
4

1 回答 1

1
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

在此处查看小提琴。

于 2013-11-09T16:43:34.950 回答