How can duplicate results in a different order be removed in a Cypher response?

六眼飞鱼酱① 提交于 2019-12-02 13:51:58

问题


I am trying to find all the videos which 2 people commonly liked using the following cypher query

MATCH (p1: person)-[:LIKED]->(v)<-[:LIKED]-(p2: person)
return p1, p2, v

In the output each entry is listed twice, with the values of p1 and p2 being switched. Example:

BOB | Mary | Cat video
Mary| Bob  | Cat video

How can such duplicate entries combined into one?


回答1:


Here is one way to prevent duplicate results:

MATCH (p1: person)-[:LIKED]->(v)<-[:LIKED]-(p2: person)
WHERE ID(p1) < ID(p2)
RETURN p1, p2, v;

This works by requiring p1 to have a lower native ID than p2.



来源:https://stackoverflow.com/questions/41603136/how-can-duplicate-results-in-a-different-order-be-removed-in-a-cypher-response

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!