I think Tom almost had it...either:

WITH 'A' as name 
          MATCH p=((n:Root)-[:CHILD*]->(m {name:name})) 
          WHERE SINGLE(n in nodes(p) WHERE n.name=name) 
          RETURN m

or maybe:

WITH 'A' as name 
          MATCH p=((n:Root)-[:CHILD*]->(m {name:name})) 
          WHERE NONE(n in TAIL(nodes(p)) WHERE n.name=name) 
          RETURN m

On Tuesday, December 27, 2016 at 8:07:07 AM UTC-6, Behrang Saeedzadeh wrote:
>
> For some reason this is returning such nodes too:
>
>  /ROOT/N1/A/N2/A
>
> I will upload the database sometime later. I think that should make it 
> easier to test the queries.
>
> On Tuesday, December 27, 2016 at 10:45:25 PM UTC+11, Tom Zeppenfeldt wrote:
>>
>> What about this approach ?
>>
>>
>>           WITH 'A' as name 
>>           MATCH p=((n:Root)-[:CHILD*]->(m {name:name})) 
>>           WHERE SINGLE(n in TAIL(nodes(p)) WHERE n.name=name) 
>>           RETURN m
>>
>> which wil return only the first node with name=‘A’  , if any.
>>
>> On 27 Dec 2016, at 11:58, Behrang Saeedzadeh <[email protected]> wrote:
>>
>> This might work, but my dataset has about 2m nodes and it is very slow as 
>> it results a cartesian join:
>>
>> MATCH (n), (p)
>> WHERE
>>  n.name = 'A' AND
>>  p.name = 'A' AND
>>  NOT (p)-->(n)
>> RETURN n
>>
>>
>>
>> On Tuesday, December 27, 2016 at 9:52:08 PM UTC+11, Behrang Saeedzadeh 
>> wrote:
>>>
>>> Hi Benoit,
>>>
>>> A is the value of the name property for the nodes. So the query is more 
>>> like this:
>>>
>>>
>>> MATCH (n)
>>> WHERE
>>>  size ((m)-->(n)) = 0
>>>  AND m.name = 'A'
>>>  AND n.name = 'A'
>>> RETURN n
>>>
>>>
>>> However this won't work because I don't have m in the MATCH clause:
>>>
>>> Variable `m` not defined (line 3, column 9 (offset: 24))
>>> " size ((m)-->(n)) = 0"
>>>          ^
>>>
>>>
>>>
>>>
>>> On Saturday, December 24, 2016 at 9:33:47 PM UTC+11, Benoît Simard wrote:
>>>>
>>>> Something like that ?
>>>>
>>>> MATCH (n:A)
>>>> WHERE 
>>>>   size((:A)-->(n)) = 0 AND
>>>>  exists((:Root)-[*]->(n))
>>>> RETURN n
>>>>
>>>>
>>>>
>>>> 2016-12-24 10:40 GMT+01:00 Behrang Saeedzadeh <[email protected]>:
>>>>
>>>>> Let's pretend we have a tree like this in which each node is labeled 
>>>>> with the name property:
>>>>>
>>>>>
>>>>> ROOT
>>>>> |
>>>>> \---> X --> *A* --> Y --> A --> Z
>>>>> |
>>>>> |
>>>>> \---> *A* --> A
>>>>> |
>>>>> |
>>>>> \---> *A*
>>>>>
>>>>>
>>>>> I want to return all the nodes named A that don't have an ancestor 
>>>>> that is also named A. In other words, only the *A* nodes that are in 
>>>>> bold and are underlined.
>>>>>
>>>>> What Cypher query can return these nodes? 
>>>>>
>>>>> Thanks in advance.
>>>>>
>>>>> -- 
>>>>> You received this message because you are subscribed to the Google 
>>>>> Groups "Neo4j" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>>> an email to [email protected].
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>>
>>>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Neo4j" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to