Search code examples
neo4jcypherrelationshipfraud-prevention

Find nodes that have more than one path to some end point


I have this relationship:

(s)-[:ES_SOCIO_DE]->(p)-[:OFERTA_A]->(l)

's' owns 'p' and 'p' offers products to 'l'

's' could have more then one 'p' and through that offers to the same 'l'

I want to find all the cases in which 's' relates to 'l' through different 'p'

This is a graphical representation of my problem:

I want to find all this kind of relations

Is that posible? And if it is, how can I do it?

Thanks in advance for all help that you can provide.


Solution

  • You can use a query of this form:

    MATCH (s:Socios)-[:ES_SOCIO_DE]->(p1:Proveedor)-[:OFERTA_A]->(lic)<-[:OFERTA_A]-(p2)<-[:ES_SOCIO_DE]-(s)
    WHERE ID(p1) <> ID(p2)
    RETURN s,lic,p1,p2;
    

    That should should get you what are looking for.

    If you need a different set of variables returned, substitute them in the RETURN clause.