Return results only if a specific node exists in a specific path

17 views
Skip to first unread message

Michael Azerhad

unread,
Jun 6, 2014, 7:25:32 AM6/6/14
to ne...@googlegroups.com
MATCH (user)-[:PARTICIPATES]->(meeting:Meeting {id: "123"})
RETURN user

This query returns all users participating to the Meeting `123`.

Now I want to return all users participating to the Meeting `123` ONLY if user `456` participates in it.

So concretely, if user1, user2 and user3 participates to the Meeting `123`, I don't want to return them.

However if  user1, user456 and user3 participates, I want to return all of them (since `456` exists).


How could I achieve this query? 
I thought about `WHERE` mixed with `ANY` but didn't succeed.

Michael Hunger

unread,
Jun 6, 2014, 7:42:29 AM6/6/14
to ne...@googlegroups.com
MATCH (:User {id: "456"})-[:PARTICIPATES]->(meeting:Meeting {id: "123"})
MATCH (user)-[:PARTICIPATES]->(meeting)
RETURN user


Sent from mobile device
--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael Azerhad

unread,
Jun 6, 2014, 8:42:28 AM6/6/14
to ne...@googlegroups.com
Hi Michael :)

Great, works like a charm.

I reduced it to: 

MATCH (:User {id: "456"})-[:PARTICIPATES]->(meeting:Meeting {id: "123"}), (user)-[:PARTICIPATES]->(meeting)
RETURN user

Thanks a lot,

Michael

Michael Hunger

unread,
Jun 6, 2014, 10:15:49 AM6/6/14
to ne...@googlegroups.com
But then 456 is not returned, or?

Sent from mobile device

Michael Azerhad

unread,
Jun 6, 2014, 11:32:49 AM6/6/14
to ne...@googlegroups.com
456 was well returned. 
However, I change the query to specify the condition in a where clause : 
MATCH (user)-[:PARTICIPATES]->(meeting:Meeting {id: "123"})
WHERE {:User {id: "456"}}-[:PARTICIPATES]->(meeting) 
RETURN user

Leading to the same result as yours 
You received this message because you are subscribed to a topic in the Google Groups "Neo4j" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/neo4j/93mjGP7YPG8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to neo4j+un...@googlegroups.com.

Michael Hunger

unread,
Jun 6, 2014, 12:23:57 PM6/6/14
to ne...@googlegroups.com
That's more expensive then you should see it profile

Sent from mobile device

Michael Azerhad

unread,
Jun 6, 2014, 1:39:42 PM6/6/14
to ne...@googlegroups.com
Yes, I agree.

But for the quantity of data I have until now, the difference is very very little.
Reply all
Reply to author
Forward
0 new messages