如何在Cypher响应中删除不同顺序的重复结果? [英] How can duplicate results in a different order be removed in a Cypher response?

查看:161
本文介绍了如何在Cypher响应中删除不同顺序的重复结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过以下密码查询查找2个人通常喜欢的所有视频

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

在输出中,每个条目列出两次,p1和p2的值被切换。示例:

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?

推荐答案

这是一种防止重复结果的方法:

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;

这可以通过要求 p1 较原生ID低于 p2

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

这篇关于如何在Cypher响应中删除不同顺序的重复结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆