'Returning multiple columns

Hi All newbie here in Neo4J, I am trying to return keys or properties using the following simple query in the neo4J broswer environment.

MATCH (n:movies),(m:people)
RETURN properties(n,m)

What I am trying to achieve is to return the properties for both the movies and people nodes However, I would always get an error

Too many parameters for function 'properties' (line 2, column 9 (offset: 36))
" RETURN properties(n,m)"

I have tried,

MATCH (n:movies),(m:people)
RETURN properties(k) in [n,m]

The error I would get

Variable `k` not defined (line 2, column 20 (offset: 47))
" RETURN properties(k) in [n,m]"

I am trying to pass a list here into k but NEO4J is not permitting me to do so. Is it even possible to pass a list into the function properties() ??

Thank you in advance.



Solution 1:[1]

The properties function takes exactly one node or a relationship as input.

MATCH (n:movies),(m:people) RETURN properties(n), properties(m)

will create a Cartesian Product.
i.e. If you have five movies and ten people, you will get a result of all 50 combinations.

If you aren't looking for a cartesian product, you would have to define a specific pattern or restrict the MATCH clause further.

If you want just the individual properties without combining them, consider Union.

MATCH (n:Movie)
RETURN properties(n) as `Properties`
UNION ALL
MATCH (m:Person)
RETURN properties(m) as `Properties`

Why am I using aliases for a seemingly simple query? To avoid this:

All sub queries in an UNION must have the same column names (line 3, column 1 (offset: 39))

For working with lists: The collect function lets you create/construct a list from the results while UNWIND expands a list into a sequence of rows.

Solution 2:[2]

properties() only takes one argument, you can try

MATCH (n:movies),(m:people) RETURN properties(n) as prop_n, properties(m) as prop_m 

or more optimal query would be

MATCH (n:movies) optional match (m:people) RETURN properties(n) as prop_n, properties(m) as prop_m 

MATCH (n:movies),(m:people)
RETURN properties(k) in [n,m]

since you have not defined k so you are getting the error. Also according to doc properites() takes "An expression that returns a relationship, a node, or a map" as an argument. Your query is not supported.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Thennan
Solution 2 micro5