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

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

问题描述

我正在尝试使用以下密码查询找到两个人普遍喜欢的所有视频

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 具有低于 p2 的本机 ID 来实现的.

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

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

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