Reputation: 12304
This is my graph
I am trying to make a query that tells me if the connections from a node of type T
exist to nodes of type M
. I heard that OPTIONAL MATCH
is equivalent to SQL Left Join, but it does not include the the missing link.
Here is my attempt:
START t=node(241)
OPTIONAL MATCH t-[r:R]->(m)
RETURN m.name, r is not NULL
and the result only has nodes M1
, M2
, M3
.
I also want to include the row M4 | false
in the result.
If I modify the query a bit
START t=node(241), m=node(246,247, 248, 249)
OPTIONAL MATCH t-[r:R]->(m)
RETURN m.name, r is not NULL
then I can get the desirable result, but it requires me to know the ids of all the M nodes in advance.
Upvotes: 2
Views: 1097
Reputation: 12304
I felt kinda dump because I found the answer right after posting this.
All I need is an extra match to get all M nodes.
START t=node(241)
MATCH (m:M)
OPTIONAL MATCH t-[r:R]->(m)
RETURN m.name, r is not NULL
Upvotes: 3