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.

Cartesian product while referencing the same relation with different constraints

I am completely new to Neo4j. The current graph version is 4.0.1 Enterprise. The issue being faced by me is that of cypher query.
The data can be viewed using the following link
Below are some screenshots that help understand the data.
call db.schema.visualization()
2X_1_175bdf6055d6f97687454240fed7966097b711b9.png
one Person above can be linked only to one type.




This image shows the person count per type.




This is the part where I am facing the issue

MATCH (p1:PERSON)<-- (:TYPE{name:"t1"})
MATCH (P2:PERSON)<-- (:TYPE{name:"t2"})
RETURN COUNT(p1), COUNT(P2)

Here I get the result as 1786(38*47) for both the counts. I need the first column to have value 38 and the other to have 47.

P.S.: This is a dummy problem recreated to mimic a real-world situation of creating a self-join of one person with another from the other type. The CSV load is taking too much time thus even though that is a simpler way the computation time is so much that the desktop is not able to process it even though I have set heap space of 8GB space.

Thanks in advance for the help.

1 ACCEPTED SOLUTION

MATCH (p1:PERSON)<-- (:TYPE{name:"t1"})
WITH COUNT(p1) as p1_count
MATCH (P2:PERSON)<-- (:TYPE{name:"t2"})
RETURN p1_count, count(p2) as p2_count

You can try this.

View solution in original post

2 REPLIES 2

MATCH (p1:PERSON)<-- (:TYPE{name:"t1"})
WITH COUNT(p1) as p1_count
MATCH (P2:PERSON)<-- (:TYPE{name:"t2"})
RETURN p1_count, count(p2) as p2_count

You can try this.

Thank you for the help @jaini.kiran !!
Does this have a constraint that it can only be used for aggregation or single result cause I am not able to return the nodes in this scenario thus Relation building is becoming challenging