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]

Hello @nboubakr :slightly_smiling_face:

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

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