cancel
Showing results forΒ
Did you mean:Β

## Can someone help me with this query please?

I am a newcomer to Neo4J but have been making good progress. I need some help with this one though.

The following query is supposed to return me 2 independent counts in a single query but returns pcount=0 and gcount=0 when I am looking for pcount=1 and gcount=0.

If I run each "half" of the query individually, I get the correct results.

// Person

MATCH (p:Person)
WHERE p.lat > -90
WITH p
MATCH (p:Person)-[:SKILL]-(skill:Skill) WHERE skill.skillId IN ['instrument_accompanist']
WITH p
// If I RETURN count(p) here, I get '1' as expected.
// Gig (should return nothing)
MATCH (g:Gig)
WHERE g.lat > -90
WITH g, p
MATCH (g:Gig)-[:SKILL]-(skill:Skill) WHERE skill.skillId IN ['instrument_accompanist']
WITH p, g
RETURN count(p) as pcount, count(g) as gcount

I believe that the cartesian product is empty, but I can't figure out using collect/distinct etc how on earth to solve it.

1 ACCEPTED SOLUTION
Ninja

Try this:

``````call{
MATCH (p:Person)
WHERE p.lat > -90
AND EXISTS {
(p)-[:SKILL]-(skill:Skill)
WHERE skill.skillId IN ['instrument_accompanist']
}
RETURN 'person' as type, count(p) as count

UNION ALL

MATCH (g:Gig)
WHERE g.lat > -90
AND EXISTS {
(g)-[:SKILL]-(skill:Skill)
WHERE skill.skillId IN ['instrument_accompanist']
}
RETURN 'gig' as type, count(g) as count
}
return type, count``````
3 REPLIES 3
Ninja

Try this:

``````call{
MATCH (p:Person)
WHERE p.lat > -90
AND EXISTS {
(p)-[:SKILL]-(skill:Skill)
WHERE skill.skillId IN ['instrument_accompanist']
}
RETURN 'person' as type, count(p) as count

UNION ALL

MATCH (g:Gig)
WHERE g.lat > -90
AND EXISTS {
(g)-[:SKILL]-(skill:Skill)
WHERE skill.skillId IN ['instrument_accompanist']
}
RETURN 'gig' as type, count(g) as count
}
return type, count``````