which is partially right but also includes a bunch of players who played for the opposition rather than for Arsenal.

The reason for this is that we’re following the ‘played_in’ relationship from the games and that relationship doesn’t distinguish between players playing for a specific team in the match.

I initially tried to reduce the number of rows returned by adding to the MATCH clause like this:

START team = node:teams('name:"Arsenal"')
MATCH team-[:home_team|away_team]-game-[:played_in]-player,
player-[:played]-()-[:for]-team
RETURN player.name, COUNT(player.name) as games
ORDER BY games desc

This did work to an extent – it now returned only Arsenal players but the count of games was completely wrong:

The reason this doesn’t work is that for every Team -> Game -> Player traversal in the first MATCH clauses we are doing a Player->Stats->Team traversal.

Taking Cazorla as an example: the first traversal matches 25 paths and then the second traversal also matches 25 paths.

The reason we end up with 625 matching paths for him is that we’re doing that second traversal 25 times, once for each of the matching paths from the first traversal.

What we actually need to do is make that second MATCH clause a WHERE clause which I hadn’t realised was possible until a few days ago.

In all the previous queries I’ve written with cypher I only ever used the WHERE clause to filter based on node or relationship properties.

If we make this change we end up with the following query

START team = node:teams('name:"Arsenal"')
MATCH team-[:home_team|away_team]-game-[:played_in]-player
WHERE player-[:played]-()-[:for]-team
RETURN player.name, COUNT(player.name) as games
ORDER BY games desc