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 .

@ankit.varshney83

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

MATCH (p:Person)
  WHERE p.name CONTAINS 'Tom'
WITH collect(p.name) AS names
UNWIND names AS onename
MATCH (p:Person)--(m:Movie)
  WHERE p.name = onename
RETURN p.name, 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)
MATCH (ex11)-[:FKCOLUMNS_CLIENTID_TO_CLIENTID]->(c)

RETURN ex11, c, cost

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