简体   繁体   English

如何在此示例中连接两个表

[英]How to join two tables in this example

I got a problem getting records out of two tables correctly. 我有一个问题,正确地从两个表中获取记录。

I need to get a list in which every device and its software is linked. 我需要获得一个列表,其中每个设备及其软件都链接在一起。

Hard to explain what my goal is, but i hope you will understand my Example. 很难解释我的目标是什么,但我希望你能理解我的例子。

Example: 例:

在此输入图像描述

You need a join with multiple instances of table2 您需要具有table2的多个实例的连接

select b.name,c.name
from table1 a inner join table2 b on a.targetid=b.objectid
inner join table2 c on a.assignedid=c.objectid

JOIN the Table2 two times with Table1 and add the proper alias names will solve in your request. 使用Table1 Table2两次,并在您的请求中添加正确的别名。

The working query is: 工作查询是:

SELECT T2.Name AS ComputerName, T3.Name AS SoftwareName
FROM Table1 T1
JOIN Table2 T2 T2.ObjectId = T1.TargetId
JOIN Table2 T3 T3.ObjectId = T1.AssignedId

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM