# Create a query that brings data from two different nodes that doesn't have any relationship

**URL:** <https://community.neo4j.com/t/create-a-query-that-brings-data-from-two-different-nodes-that-doesnt-have-any-relationship/56460>\
**Category:** Cypher\
**Tags:** cypher\
**Created:** [May 17, 2022, 6:10pm UTC](https://community.neo4j.com/t/create-a-query-that-brings-data-from-two-different-nodes-that-doesnt-have-any-relationship/56460 "2022-05-17T18:10:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![igorbmartins](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/igorbmartins/32/23967_2.png) [@igorbmartins](https://community.neo4j.com/u/igorbmartins)\
**Post date:** [May 17, 2022, 6:10pm UTC](https://community.neo4j.com/t/create-a-query-that-brings-data-from-two-different-nodes-that-doesnt-have-any-relationship/56460/1 "2022-05-17T18:10:10Z")

</div>

Hello guys, it’s me again.

Now, I would like to make a select “match” with two situations. I am mean, with two different nodes. The bellow query give me my answer, but I need to execute two separate query. Instead of that I need to execute only one query to return both answers. Is it possible?

match ( **pu:PessoaUnica** {CPF:'00000000001'}) return pu;

match ( **po:PessoaOrigem** {CPF:'00000000001'}) return po;

Before asking this help, I try to find the answers on the internet and the closer that I found was using union all, but to use it the return must be equal so it doesn’t work for my business.

Regards,

Igor Bastos Martins

---

<div class="post-metadata">

**Author:** ![dana\_canzano](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/dana_canzano/32/27392_2.png) [@dana\_canzano](https://community.neo4j.com/u/dana_canzano)\
**Post date:** [May 17, 2022, 6:48pm UTC](https://community.neo4j.com/t/create-a-query-that-brings-data-from-two-different-nodes-that-doesnt-have-any-relationship/56460/2 "2022-05-17T18:48:17Z")

</div>

@igorbmartins

> **[UNION - Cypher Manual](https://neo4j.com/docs/cypher-manual/current/clauses/union/)**
>
> The \`UNION\` clause is used to combine the result of multiple queries.

```auto
UNION combines the results of two or more queries into a single result set that includes 
all the rows that belong to all queries in the union.

The number and the names of the columns must be identical in all queries 
combined by using UNION.

```

---

<div class="post-metadata">

**Author:** ![igorbmartins](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/igorbmartins/32/23967_2.png) [@igorbmartins](https://community.neo4j.com/u/igorbmartins)\
**Post date:** [May 17, 2022, 6:56pm UTC](https://community.neo4j.com/t/create-a-query-that-brings-data-from-two-different-nodes-that-doesnt-have-any-relationship/56460/3 "2022-05-17T18:56:39Z")

</div>

Hello dana.canzano, the problem to use UNION ALL it is because they have a premiss that all columns must be identical in both query. In my case it is not true. In the first query I want as result the node X and in the second query the result is Y.  
Do you know some way to do that?

---

<div class="post-metadata">

**Author:** ![dana\_canzano](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/dana_canzano/32/27392_2.png) [@dana\_canzano](https://community.neo4j.com/u/dana_canzano)\
**Post date:** [May 17, 2022, 8:03pm UTC](https://community.neo4j.com/t/create-a-query-that-brings-data-from-two-different-nodes-that-doesnt-have-any-relationship/56460/4 "2022-05-17T20:03:55Z")

</div>

@igorbmartins

the requirement is the name and number of columns returned is the same. You can however rename as column using the `as clause` , i.e `match (n:Person) return n.name as fullname;` for the query will rename the returning column n.name to fullname

---

<div class="post-metadata">

**Author:** ![rogelio\_basurto](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/rogelio_basurto/32/4248_2.png) [@rogelio\_basurto](https://community.neo4j.com/u/rogelio_basurto)\
**Post date:** [May 17, 2022, 8:40pm UTC](https://community.neo4j.com/t/create-a-query-that-brings-data-from-two-different-nodes-that-doesnt-have-any-relationship/56460/5 "2022-05-17T20:40:10Z")

</div>

Maybe you can use the WITH clause, something like this:

```auto
MATCH (n)-[]-(m) WHERE X
WITH n
MATCH (a)-[]-(b) WHERE Y
WITH n,a
RETURN n.name, a.age

```

---

<div class="post-metadata">

**Author:** ![igorbmartins](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/igorbmartins/32/23967_2.png) [@igorbmartins](https://community.neo4j.com/u/igorbmartins)\
**Post date:** [May 18, 2022, 11:36am UTC](https://community.neo4j.com/t/create-a-query-that-brings-data-from-two-different-nodes-that-doesnt-have-any-relationship/56460/6 "2022-05-18T11:36:29Z")

</div>

Hi Rogerio, I solve this problem putting an alias like:

match ( **pu:PessoaUnica** {CPF:'00000000001'}) return pu as **po**  
union all  
match ( **po:PessoaOrigem** {CPF:'00000000001'}) return po

Thanks
