Merge tow cypher statement into single

Hi I have requirement ,
I am new in Neo 4 j , I need to merge two query

Query 1= "MATCH (c:client{clientID:"+ClientID+"})<-[:OFFERED_AT]-(p:empname{empID:"+inputID+"})<-[:COST_FOR_PLAN]-(ex:expendeture)-[:COST_APPLIES_TO_BC]->(plan:plan{planID:"+inputPlanID+"}) return cs order by cs.effectiveDate desc"

Query 2= "MATCH (c:client{clientID:"+ClientID+"})<-[:FKCOLUMNS_CLIENTID_TO_CLIENTID]-(ex:expendeture{ExpenseID:<OUTPUT OF QUERY 1>})<-[:DETAILS_FOR]-(cost:rcost) where not exists(cost.IsDeleted) return tc"

Out of query 1 is list of records from which current id need to pass in second query paramater

Currently i am executed these statement separately from my application . I want to avoid then separate execution want to execute in single operation

Can any one help how can we achieve this .


You can connect the two statements with the WITH and UNWIND clause
In this example, 'names' and 'onename' is the parameter.

MATCH (p:Person)
WITH collect( AS names
UNWIND names AS onename
MATCH (p:Person)--(m:Movie)
  WHERE = onename
RETURN, m.title

the 'names' is a list.

["Tom Cruise", "Tom Skerritt", "Tom Hanks", "Tom Tykwer"]
Try this:

I split your queries for my understanding:

//Query 1......
MATCH (p:empname{empID:"+inputID+"})-[:OFFERED_AT]->(c:client{clientID:"+ClientID+"})
MATCH (ex:expendeture)-[:COST_FOR_PLAN]->(p)
MATCH (ex)-[:COST_APPLIES_TO_BC]->(plan:plan{planID:"+inputPlanID+"})
WITH c, ex order by ex.effectiveDate desc
WITH COLLECT(ex) as ex1, c
UNWIND ex1 as ex11

//Query 2...........
MATCH (cost:rcost)-[:DETAILS_FOR]->(ex11) 
WHERE NOT EXISTS(cost.IsDeleted)

RETURN ex11, c, cost

Your RETURN variables cs and tc not defined. Check and see if this works!