How to merge/omit duplicate sub graph path from query result and form a new parent graph path

Hi all,

I'm trying to get a parent graph out from my resultant sub graph, combining all common parts of sub graph path.

Like to know the best way to do it?

here the basic query:

MATCH path = (s:startPoint {id:'123'}) - [:CONNECTED*] - (e:endPoint)

In database there is multiple end points(count: 500).

That query giving me 500 path(s), where maximum of the paths using the same sub-route.

As a result it's giving me lots of duplicate nodes.

Right now I'm using the following query for getting the result I wanted.

But, I believe this can be improved.

MATCH path = (s:startPoint {id:'123'}) - [:CONNECTED*] - (e:endPoint)
WITH path
UNWIND relationships(path) as paths
with DISTINCT paths as distinctPath
MATCH p = () - [distinctPath] - ()
return p

Please let me know your comments.