cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Finding Duplicate Relationships

I am trying to find all :DerivedValue nodes have more than one relationship to :SourceValue Nodes that come from the same Database.

Is there an Apoc version or better way anyone can see to run this query?
It takes several minutes to run, and also creates a duplicate of each result (reversing the Record1 & 2).

MATCH (s1:SourceValue)<-[:DERIVED_FROM]-(d:DerivedValue)-[:DERIVED_FROM]->(s2:SourceValue)
WHERE s1 <> s2 and s1.database = s2.database
RETURN d.value as IP_Hostname, s1.key as Record1, s2.key as Record2, s1.database as Database

This below would be even more ideal bc then I don't have to further find a way to split the data that comes from the s1 and s2 key, because the :Record value is cleaner.
(ie- s1.key = ip.2313125 & r.value = 2313125)

MATCH (s1:SourceValue)<-[:DERIVED_FROM]-(d:DerivedValue)-[:DERIVED_FROM]->(s2:SourceValue)
WHERE s1 <> s2 and s1.database = s2.database
RETURN d.value as IP_Hostname, s1.key as Record1, s2.key as Record2, s1.database as Database
1 REPLY 1

CORRECTION: For the second one, it that I would ideally like a better way to do it should look like this:

MATCH (r1:Record)<-[:OWNED_BY]-(s1:SourceValue)<-[:DERIVED_FROM]-(d:DerivedValue)-[:DERIVED_FROM]->(s2:SourceValue)-[:OWNED_BY]->(r2:Record)
WHERE s1 <> s2 and s1.database = s2.database
RETURN d.value as value, r1.value as Record1, r2.value as Record2, r1.database as Database```