简体   繁体   English

为什么重复结果查询 cypher neo4j

[英]Why duplicated results query with cypher neo4j

I am implementing the example database Movies en Neo4j. I already search something about duplicated rows but I still have doubts我正在实施示例数据库 Movies en Neo4j。我已经搜索了一些关于重复行的内容,但我仍然有疑问

I am using XOR .我正在使用XOR I am getting the我得到了

MATCH (m:Movie)<-[r]-(p:Person)
WHERE m.title STARTS WITH 'The' 
XOR (m.released = 1999 OR m.released = 2003)
RETURN m.title, m.released
So, my result is

在此处输入图像描述

As you can see, there are duplicated rows, I don't understand why there are doing that and the number of duplicated results is according to what?如您所见,有重复的行,我不明白为什么要这样做,重复结果的数量是根据什么?

I know that DISTINCT removes duplicated.我知道 DISTINCT 会删除重复项。 But I am interested in understanding why the query duplicated the results and the number of duplicated is according to what?.但我有兴趣了解为什么查询重复结果以及重复的数量是根据什么?。

This is because you are matching这是因为你匹配

MATCH (m:Movie)<-[r]-(p:Person)

So the movie title will be returned for each person in the movie, so if there are 4 people in the movie, you will get four movie titles back.所以电影中的每个人都会返回电影名称,所以如果电影中有 4 个人,你会得到四个电影名称。 You can remove duplicates by matching only the movie您可以通过仅匹配电影来删除重复项

MATCH (m:Movie)

As Tomaz said, it is returning a row for every:Person that has a relationship to:Movie.正如 Tomaz 所说,它为每一个返回一行:与:Movie 有关系的人。 If you concluded your query with just RETURN m and viewed the results, you probably would only see non-duplicated nodes appear.如果您仅使用RETURN m结束查询并查看结果,您可能只会看到未重复的节点出现。 Otherwise, you can conclude the query with RETURN DISTINCT m to ensure that non-duplicated results are returned.否则,您可以使用RETURN DISTINCT m结束查询,以确保返回不重复的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM