2

My simple database contains nodes of 'terms' and 'codes' linked to each other. There are two types of relationships.

Relationships between 'terms' and 'codes' called :CODE and are undirected (or read in both directions equally). Relationships between 'terms' called :NT (which means narrow term) and are directed.

I want to get the list of all terms which are connected by :NT relationships and have equal codes. This is pretty simple query in SQL Server but next I want to extend by all :NT* relationships. That's why I'm using Neo4j.

If I run the query below it is OK, except many duplicate rows.

MATCH (a)-[:NT]->(b), (a)-[:CODE]-(c), (b)-[:CODE]-(c)
RETURN DISTINCT a.termid AS termid, c.code AS code
UNION ALL
MATCH (a)-[:NT]->(b), (a)-[:CODE]-(c), (b)-[:CODE]-(c)
RETURN DISTINCT b.termid AS termid, c.code AS code
ORDER BY termid;

I want to remove duplicate rows in the result set.

This is absolutely same action as Data->Remove Duplicates in MS Excel.

I can not implement it in Neo4j that easy.

Thank you for your help!

master-lame-master
  • 3,101
  • 2
  • 30
  • 47

1 Answers1

2

You could use UNION instead of UNION ALL and that would return a unique set across the two. Do you want intersection though instead?

Dave Bennett
  • 10,996
  • 3
  • 30
  • 41