Cypher query like a left join in SQL query

Hello everybody, how are you?

Gus, I would like to create a cypher query similar to a left join in a SQL Query. I made the bellow query but the result is not what I want. After the query I will explain what is wrong for me.

// Return data from a specífic CPF
match (po:PessoaOrigem {CPF:'00000000001'}) //filterin people that have a specific CPF
match (c:ContratoOrigem) //Contract Node
match (ctt:ContatoEletronicoOrigem) //Email node
WHERE (NOT (po)-[:GOLDEN]->(:PessoaUnica)) //filtering a specifc situation that for me is mandatory, my major filter
and ((po)-[:POSSUI_CONTRATO]->(c)) // filtering relationship but I don't what to use it
and ((po)-[:EMAIL]->(ctt)) // filtering relationship but I don't what to use it
return po as pu, c, ctt

In the node po:PessoaOrigem there are 100 people, where oly six have CPF = '0000000001'. From those 5 people 3 have a relationship with node :PessoaUnica, that I don't want to see, so it last two people that have the specifc CPF and that don't have relationship with PessoaUnica.
From those 2 people I would like to see other informations like contracts and email, but if the person don't have this information "nodes" I also want to continue to see its data. It is something like a left join.

Could someone help me?

Igor Martins


see OPTIONAL MATCH - Cypher Manual

1 Like

Thank you man.
Using OPTIONAL MATCH the query works prorpely.