Question

I have a node with id 1 and a node with id 2 in the database and they are linked to each other. Why when I run this query

MATCH (a)-[r]-(b) WHERE id(a)=1 AND id(b)=2 RETURN *;

Nothing is returned?

Solution

I use GrapheneDB. Usually GrapheneDB presents the system node id on the node graphic but when you have an attribute id it presents that instead. When I ran the query I was using the graphic id which wasn't actually the system id so id(a) didn't give the expected result.

Was it helpful?

Solution

Because the WHERE clause is evaluated for each candidate result, and the entire clause must evaluate to true.

Also, putting MATCH (a)-[r]-(b) will only find parts of the graph where those two nodes are related.

If you just want to find nodes 1 and 2, you can do this:

MATCH n
WHERE id(n) = 1 OR id(n) = 2
RETURN n

However, you should not be using node ids. They are deprecated, and being phased out. There are lots of other ways to find and identify nodes that don't rely on their internal identifier. If you open a new question with your actual scenario, we could help you write a better query.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top