cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to match multiple queries?

q6qgs
Node Link
MATCH (p:Project{id:"p1test"})<-[r1:TICKET]-(:Ticket)
MATCH (u:User{id:"user1test"})
WITH u, COUNT(r1) + 1 AS issNo, p
CREATE (p)<-[rel:TICKET]-(t: Ticket {id:apoc.create.uuid(), title:"T1", hourEstimate:9, desc:"hELLO", done:false, issueNumber: issNo })<-[:CREATED {timestamp: apoc.date.currentTimestamp()}]-(u)
RETURN t

This statement returns no mathcing record, and none of the nodes or relationships get created..

I'm trying to create a ticket node, with an issue number property that matches the number of tickets already related to project node + 1.

Please Help

Many Thanks

6 REPLIES 6

intouch_vivek
Graph Steward

Hi @q6qgs,

First 2 line of your code is trying to join two datasets coming from match. As there is no relationship visible between it will not return any row.
MATCH (p:Project{id:"p1test"})<-[r1:TICKET]-(:Ticket)
MATCH (u:User{id:"user1test"})

In fact if you try below it will not give you any result.
MATCH (p:Project{id:"p1test"})<-[r1:TICKET]-(:Ticket)
MATCH (u:User{id:"user1test"})
Return p, u,r1

So how can I return two unrelated datasets?

One way is to use Union, however it depends on the requirement. In this return type of both the datasets must be of same type

If nothing's getting created, then one of your two MATCH patterns aren't finding any matching paths.

Try running each MATCH separately, returning the node (or nodes) in its own query. That should show you which one is finding no matches in the graph.

Then it's up to you to figure out why it's not finding any nodes. Typos in the query? Typos in your graph data? Does the project not have any tickets? Something is off there. Once you fix whatever needs fixing such that both MATCHes can find results in the graph, then your query should work.

This is what worked for me in the end :

MATCH (p:Project),(u:User)
WHERE p.id = 'p1test' AND u.id = 'user1test'
CREATE (p)<-[:TICKET]-(t: Ticket {id:apoc.create.uuid(), title:"t1", hourEstimate:9, desc:"hello", done:false})<-[:CREATED {timestamp: apoc.date.currentTimestamp()}]-(u)
WITH p, t
MATCH (p)<-[r1:TICKET]-(:Ticket)
WITH COUNT(r1) AS issNo,t
SET t.issueNumber = issNo 
RETURN t

Would be nice to condense it down.. does anyone have any thoughts?

rushikesh
Node Clone

hey @q6qgs, if you are trying to create a new ticket for the project having no tickets, this match query gives you null. That's why this statement does not create any node and relationship.

on the other hand, here you first create a ticket for a particular project and then you try to find pattern with match clause, that's why you always get the result