Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
05-17-2022 11:10 AM
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
Solved! Go to Solution.
05-18-2022 04:36 AM
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
05-17-2022 11:48 AM
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.
05-17-2022 11:56 AM
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?
05-17-2022 01:03 PM
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
05-17-2022 01:40 PM
Maybe you can use the WITH clause, something like this:
MATCH (n)-[]-(m) WHERE X
WITH n
MATCH (a)-[]-(b) WHERE Y
WITH n,a
RETURN n.name, a.age
05-18-2022 04:36 AM
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
All the sessions of the conference are now available online