1
所以我有一个加入,它的工作原理,但它并没有显示我想要的所有数据。目前我想查看device_interface.c1
中的每一行,如果device_interface.c1 = device_inventory.c1
那么我想在列中看到。现在我只看到device_interface.c1 = device_inventory.c1
。postgresql - 在匹配上加入表,但也不匹配?
下面是我的查询:
SELECT
device_info.pk,
device_interface.fk,
device_interface.c1,
device_interface.c2,
device_inventory.c1
FROM
"test".device_info,
"test".device_interface,
"test".device_inventory
WHERE
device_info.pk = device_interface.fk AND
device_info.pk = device_inventory.fk AND
device_interface.c1 = device_inventory.c1 AND
device_interface.c2 = 'Physical'
示例输出:期望的输出的
device_info.pk device_interface.c1 device_inventory.c1
1 1 1
1 3 3
1 95 95
2 55 55
2 634 634
实施例:
device_info.pk device_interface.c1 device_inventory.c1
1 1 1
1 2
1 3 3
1 4
1 5
1 6
1 95 95
2 55 55
2 56
2 57
2 634 634
您正在寻找的是左连接。对不起,我没有时间回答,但看看这篇关于[Visual SQL Representation of SQL Joins]的文章(https://www.codeproject.com/articles/33052/visual-representation-of-sql-joins )。 – Schwern
谢谢你我会通过 – Aladine