Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between multiple MATCH clauses and a comma in a Cypher query?

Tags:

neo4j

cypher

In a Cypher query language for Neo4j, what is the difference between one MATCH clause immediately following another like this:

MATCH (d:Document{document_ID:2}) MATCH (d)--(s:Sentence) RETURN d,s 

Versus the comma-separated patterns in the same MATCH clause? E.g.:

MATCH (d:Document{document_ID:2}),(d)--(s:Sentence) RETURN d,s 

In this simple example the result is the same. But are there any "gotchas"?

like image 435
Gene M Avatar asked Sep 23 '15 14:09

Gene M


People also ask

WHAT IS WITH clause in Cypher?

The WITH clause allows query parts to be chained together, piping the results from one to be used as starting points or criteria in the next. It is important to note that WITH affects variables in scope. Any variables not included in the WITH clause are not carried over to the rest of the query.

What does match do in Neo4j?

The MATCH clause allows you to specify the patterns Neo4j will search for in the database. This is the primary way of getting data into the current set of bindings. It is worth reading up more on the specification of the patterns themselves in Patterns.

When you create a relationship in Cypher You must specify a direction True or false?

Syntax: Creating relationships When you create the relationship, it must have direction. You can query nodes for a relationship in either direction, but you must create the relationship with a direction.

Is order by a valid Cypher clause?

You can order by multiple properties by stating each variable in the ORDER BY clause. Cypher will sort the result by the first variable listed, and for equals values, go to the next property in the ORDER BY clause, and so on. This returns the nodes, sorted first by their age, and then by their name.


1 Answers

There is a difference: comma separated matches are actually considered part of the same pattern. So for instance the guarantee that each relationship appears only once in resulting path is upheld here.

Separate MATCHes are separate operations whose paths don't form a single patterns and which don't have these guarantees.

like image 100
Michael Hunger Avatar answered Sep 30 '22 17:09

Michael Hunger