Is there a Cypher query to return a single relationship of each relationship type in a graph?
For example, I have a graph containing 5 relationships typed TYPE_X
, 10 relationships typed TYPE_Y
, and 1 relationship typed TYPE_Z
. The query would return 3 relationships:
()-[r1:TYPE_X]->()
()-[r2:TYPE_Y]->()
()-[r3:TYPE_Z]->()
It doesn't matter which TYPE_X
relationship is returned as r1
. Ideally, the query wouldn't have to scan every relationship, it would just return a single arbitrary relationship for each type.
This query would be useful for interrogating relationship types and their properties in the interactive browser.
Update based on @christophe-willemsen's answer.
I used the following query:
MATCH ()-[r]->()
RETURN type(r) AS rel_type, collect(r)[0] AS example
to generate the following visualization with one relationship for every type: