Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple unrelated queries in Neo4j Cypher?

Tags:

Does http://localhost:7474/browser/ not support multiple unrelated queries?

This code:

MATCH (a {cond:'1'}), (b {cond:'x'}) CREATE a-[:rel]->b MATCH (a {cond:'2'}), (b {cond:'y'}) CREATE a-[:rel]->b MATCH (a {cond:'3'}), (b {cond:'z'}) CREATE a-[:rel]->b 

causes an error:

WITH is required between CREATE and MATCH

But since my queries aren't related, I don't think I shall need a WITH.

How do I do the above without having to enter it one-line-at-a-time?

like image 863
laggingreflex Avatar asked Feb 14 '14 11:02

laggingreflex


People also ask

What is optional match in Neo4j?

An OPTIONAL MATCH matches patterns against your graph database, just like a MATCH does. The difference is that if no matches are found, OPTIONAL MATCH will use a null for missing parts of the pattern. OPTIONAL MATCH could be considered the Cypher equivalent of the outer join in SQL.

Which Cypher command returns data after removing duplicates?

To keep all the result rows, use UNION ALL . Using just UNION will combine and remove duplicates from the result set.

How do I return all nodes and relationships in Neo4j?

Return all elements When you want to return all nodes, relationships and paths found in a query, you can use the * symbol.

Why would you use Neo4j match?

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.


1 Answers

As a work around you can do:

MATCH (a {cond:'1'}), (b {cond:'x'}) CREATE a-[:rel]->b WITH 1 as dummy MATCH (a {cond:'2'}), (b {cond:'y'}) CREATE a-[:rel]->b WITH 1 as dummy MATCH (a {cond:'3'}), (b {cond:'z'}) CREATE a-[:rel]->b 

See also the import blog post: http://blog.neo4j.org/2014/01/importing-data-to-neo4j-spreadsheet-way.html

like image 200
Michael Hunger Avatar answered Oct 02 '22 04:10

Michael Hunger