# Optional call

**URL:** https://community.neo4j.com/t/optional-call/9812
**Category:** Cypher
**Created:** [September 2, 2019, 7:12am UTC](https://community.neo4j.com/t/optional-call/9812 "2019-09-02T07:12:46Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![shayantest2](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/shayantest2/32/5901_2.png) [@shayantest2](https://community.neo4j.com/u/shayantest2)
#### Post date: [September 2, 2019, 7:12am UTC](https://community.neo4j.com/t/optional-call/9812/1 "2019-09-02T07:12:46Z")

</div>

Assume that I want to UNION the results of two cypher queries and ORDER BY them by some property. One solution is to use a method similar to the one mentioned in [here](https://neo4j.com/blog/cypher-union-query-using-collect-clause/). In the method if we replace the MATCHes with OPTIONAL MATCH we probably can handle the case that one of the two sub-queries has an empty result. However, if in our application we need to use CALL instead of MATCH, I could not find a way for handling that case. For example, assume that we have two queries like "CALL db.index.fulltext.queryNodes(...)" and we want to UNION the results. How should we do that? Any OPTIONAL CALL?

---

<div class="post-metadata">

### Author: ![michael.hunger](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/michael.hunger/32/27377_2.png) [@michael.hunger](https://community.neo4j.com/u/michael.hunger)
#### Post date: [September 2, 2019, 3:51pm UTC](https://community.neo4j.com/t/optional-call/9812/2 "2019-09-02T15:51:02Z")

</div>

You could either wrap them in apoc.cypher.run() and collect their results internally.

Something else that should work is to use

so the first or 2nd result could result in no rows but the collect should then result in an empty collection (default value for no-rows aggregation).

```auto
call db.index.fulltext.queryNodes(...) yield node
with collect(node) as nodes
call db.index.fulltext.queryNodes(...) yield node
UNWIND collect(node) + nodes as n
RETURN n ORDER BY n.foo

```

---

<div class="post-metadata">

### Author: ![andrew\_bowman](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/andrew_bowman/32/73_2.png) [@andrew\_bowman](https://community.neo4j.com/u/andrew_bowman)
#### Post date: [September 10, 2019, 8:55am UTC](https://community.neo4j.com/t/optional-call/9812/3 "2019-09-10T08:55:14Z")

</div>

Cases where there are no results may be problematic. I don't think we have an optional mode for the fulltext query, so using `apoc.cypher.run()` to perform the UNION would probably be best, then work with the returned results from the call.

Note that there are Cypher enhancements underway for the upcoming Neo4j 4.0 at the end of the year, so subquery support should allow for a similar approach without requiring an APOC call.
