cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Select all nodes with specific property and return only those with redundant propery value

I am trying to select all nodes that have a relationship with a specific property but return only those with redundant property values. For example:

MATCH (:Node)-[a:Send{Flag: 'A'}]->(m:Node)
RETURN [m.Name, a.Port] AS output

It returns

["Device A", 22]
["Device A", 22]
["Device A", 22]
["Device A", 93]
["Device A", 93]
["Device A", 554]
["Device A", 445]

I want the output to be

["Device A", 22, 3]
["Device A", 93, 2]

 

2 REPLIES 2

Hello @nboubakr 🙂

MATCH (:Node)-[a:Send {Flag: 'A'}]->(m:Node)
WITH m.Name AS name, a.Port AS port, count(*) AS occurrences
WHERE occurrences > 1
RETURN [name, port, occurrences] AS output

Regards,

Cobra

ameyasoft
Graph Maven

Try this:

WITH distinct a.port as Port, m.name as Name, count(distinct m.name) as NameCount
RETURN Name, Port, NameCount order by Name