我在 SQL Server 中有一些节点和边缘表,它们与存储用户的标准表具有一对多的关系。每个边和节点表都有这个 1N 的关系。
我想知道如何使用匹配子句和左连接执行查询,如下所示:
SELECT * FROM Node1Table n1, EdgeTable e, Node2Table n2
LEFT JOIN UserTable usr ON e.usr = usr.ID
MATCH (n1-(e)->n2)
我可以这样写查询:
SELECT * FROM EdgeTable e
INNER JOIN Node1Table n1 ON e.$from_ID = n1.$node_ID
INNER JOIN Node2Table n2 ON e.$to_ID = n2.$node_ID
LEFT JOIN UserTable usr ON e.usr = usr.ID
但我不知道 n1 是来自还是反对。
我不能进行内部连接,因为 e.usr 可能为空
谢谢您的帮助
编辑:
测试 1:
SELECT * FROM
OBJ_APPLICATION n1, REL_APPLICATION_RESPONSABLE r INNER JOIN
Management_User u on u.[UserID] = r.[CPQ], OBJ_RESPONSABLE n2
WHERE MATCH(n1-(r)->n2)
error : The identifier "r" in a MATCH clause is used with a JOIN clause or an APPLY operator. JOIN and APPLY are not supported with MATCH clauses.
测试 2:
SELECT * FROM
OBJ_APPLICATION n1, REL_APPLICATION_RESPONSABLE r, OBJ_RESPONSABLE n2
INNER JOIN Management_User u on u.[UserID] = r.[CPQ]
WHERE MATCH(n1-(r)->n2)
error : The multi-part identifier r.CPQ could not be bound
测试 3:
SELECT * FROM
OBJ_APPLICATION n1, REL_APPLICATION_RESPONSABLE r, OBJ_RESPONSABLE n2, Management_User u
WHERE MATCH(n1-(r)->n2)
AND u.[UserID] = r.[CPQ]
Works with an INNER JOIN but in some cases I have to make a LEFT JOIN