How to MATCH more than one label type in single query with a WHERE clause on one

Hi all.

If I have a domain with UsersGroup, FileTransferTool, AssetStore and two dozen other labels with a few hundred nodes spread across these various labels, how to I select all the AssetStore nodes AND the UserGroup nodes where"XYZ".

UNION doesn’t appear to work, I believe because the number of columns on the two labels are different.

I feel stupid as this seems such a simple task and yet I've spent at least an hour searching to trying to come up with the correct syntax.

The goal is to sit with users in group XYZ, see all the available AssetStores in a visualization or table, and quickly establish STORES_ASSETS_IN relationships. And then building out further relationships to other node types from there.

I'd also be interested in tools where the above interaction with users is possible. YFiles neo4j explorer looked really promising (and still does for some use cases) but doesn't look like it will allow me to create new relationships. I suspect it's called explorer for a reason. :slight_smile:

Thanks very much.

Can you show us the Cypher you've tried so far?

Are you also looking to get :AssetStore nodes by it's name property? Or are you looking for :AssetStore nodes connected to :UserGroup nodes where you lookup the :UserGroup by name? Do you often need to lookup nodes across multiple labels by the same property and address them by the same variable, or is this a special case where you often just treat :AssetStore and :UserGroup nodes the same?

Building on this that works.

WHERE o:AssetStore OR o:DAMUserGroup
return (o)

I tried several things that are clearly wrong, but also these kinds of things.

MATCH (o,p)
WHERE o:AssetStore OR p:DAMUserGroup WHERE"XYZ"
return (o,p)

WHERE o:AssetStore OR o:DAMUserGroup WHERE"XYZ"
return (o)

This works.

So I thought this might.

MATCH (o:DAMUserGroup)
MATCH (o:AssetStore)

Nope. I've tried another just plain wrong things like not noticing I was leaving the braces off things, forgetting the RETURN... dumb stuff.

I just feel like it shouldn't be that hard. :slight_smile:

I want all the :AssetStores, but I also want just one :UserGroup, the one with a name property of XYZ.

I just want to see these specific nodes out of hundreds so I can draw in the relationships with users interactively.
Thanks for the quick response.

Try this

MATCH (a:AssetStore {name: 'XYZ'})
MATCH (u:UserGroup {name: 'XYZ'})
1 Like

That looks like it might work if I could put a wildcard or partial match on the AssetStore in this format. But there is no = sign to add =~ and use a regex. Searching now.

Below worked. Finally LOL.
I could have sworn I tried something like this but I think at the time I might not have known about the tilde ~ in for partial matches in the search.

This is a great resource. Cypher Cheat Sheet

Thanks very much for both your responses.

MATCH (a:DAMUserGroup {name: "XYZ"})
MATCH (b:AssetStore)
WHERE =~ ".*"

1 Like