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.

mrksph
Node Clone

Hi

I'm working on a query that basically groups results in two different lists that are joined before being returned.

I'm having trouble finding the way to avoid adding elements from the list #2 if there's an element in list #1 with the same specific property (a code).

Example:
List #1: [ { code:"AA", name: "Anna" }, { code:"BB", name: "Bob" } ]
List #2: [ { code:"AA", name: null }, { code:"CC", name: "Charles" } ]

Desired output:
List: [ { code:"AA", name: "Anna" }, { code:"BB", name: "Bob" }, { code:"CC", name: "Charles" } ]

Any help is appreciated
Thanks.

Comments
bennu_neo
Neo4j
Neo4j

Hi @mrksph !

You can try something like;

WITH  [{ code:"AA", name: "Anna" }, { code:"BB", name: "Bob" } ] as l1,  [ { code:"AA", name: null }, { code:"CC", name: "Charles" } ] as l2
return reduce(acc = l1, entry in [var5 in l2 where none(var3 in l1 where var3.code = var5.code)]  | acc + entry) 

Bennu

Version history
Last update:
‎05-26-2022 06:43 AM
Updated by:
Contributors