Hello,
What if instead of a single :person node, we're interested in writing one cypher query that lists more than 2 nodes without a specific relationship?
Let's say we have the nodes :person, :transaction, :city and we want the results like this table:
Name of Node | Number of Disconnected Nodes |
__________________________________
person | 55|
transaction | 43|
city | 21|
Writing the cypher query to obtain the number of disconnected nodes was straight forward, but I'm struggling with the formatting now so that I can get my results like the table above.
I got a little close to my desired results by following the instructions on this thread
I wrote this cypher query but the format is not the desired results even though it shows the correct values:
MATCH(p:person)
WHERE NOT (p)-[:executes]->(:transaction)
RETURN COUNT(DISTINCT p) AS `Disconnected Person Nodes`, NULL AS `Disconnected Transaction Nodes`, NULL AS `Disconnected City Nodes`
UNION
MATCH(p:transaction)
WHERE NOT (p)<-[:contains]-(:bank)
RETURN NULL AS `Disconnected Person Nodes`, COUNT(DISTINCT p) AS `Disconnected Transaction Nodes`, NULL AS `Disconnected City Nodes`
UNION
MATCH(p:city)
WHERE NOT (p)<-[:lives_in]-(:person)
RETURN NULL AS `Disconnected Person Nodes`, NULL AS `Disconnected Transaction Nodes`, COUNT(DISTINCT p) AS `Disconnected City Nodes`
This query gives me the following table:
Disconnected Person Nodes | Disconnected Transaction Nodes | Disconnected City Nodes |
____________________________________________________________________________________
55 | null| null|
null | 43| null|
null | null| 21|
What would be the best way to format the output as desired?
Thanks,
Tony