0

我有三个表senderTablerecieverTable和一个mapTable。我正在尝试编写查询以获取senderNamerecieverName的输出

发件人表

senderID
senderName

接收者表

recieverID
recieverName

地图表

mappingID
senderID
recieverID

我有以下查询不起作用,因为我不知道如何在其中合并映射表。

SELECT t_senderTable.nameFull AS "senderName", t_recieverTable.recieverName AS "recieverName" 
FROM ((dbo.t_senderTable AS t_senderTable
     INNER JOIN t_senderTable AS t_senderTable ON (t_senderTable.Kd = mapTable.senderID))
     INNER JOIN t_recieverTable AS t_recieverTabler ON (recieverTable.Id = mapTable.recieverID ))

有什么想法可以做对吗?谢谢

4

3 回答 3

0

我不知道你的意思是如何正确地做到这一点,如果它不工作或者有什么方法看看这个:

   SELECT s.nameFull AS senderName, r.recieverName AS recieverName 
 FROM t_senderTable AS s
 INNER JOIN mapTable as m ON s.Kd = m.senderID
 INNER JOIN t_recieverTable  as r ON r.Id = m.recieverID

在内部连接中用 mapTable摆脱() 和替换 senderTable

于 2013-06-10T19:02:25.023 回答
0

这是你想要的?

SELECT t_senderTable.nameFull AS "senderName"
     , t_recieverTable.recieverName AS "recieverName" 
  FROM dbo.t_senderTable AS t_senderTable
 INNER JOIN mapTable
    ON t_senderTable.Id = mapTable.senderID
 INNER JOIN t_recieverTable AS t_recieverTabler
    ON mapTable.recieverID = recieverTable.Id
于 2013-06-10T19:03:20.107 回答
0

用这个 :

SELECT t_senderTable.nameFull AS senderName
     , t_recieverTable.recieverName AS recieverName
  FROM dbo.t_senderTable
 INNER JOIN mapTable
    ON t_senderTable.Id = mapTable.senderID
 INNER JOIN t_recieverTable
    ON mapTable.recieverID = recieverTable.Id
于 2013-06-10T19:05:17.697 回答