0

I want to get only customer and supplier name and ID using cypher query.

"Match (n: customer:supplier) where has (n.ID) return n.ID,n.nme";

How to combine 2 labels to get the data?

Above query is getting syntax error. Please advise.

user2848031
  • 187
  • 12
  • 36
  • 69

2 Answers2

1

This for OR label matching:

MATCH (n) 
WHERE (n:customer OR n:supplier) AND exists(n.ID)
RETURN n.ID, n.nme

This for AND label matching:

MATCH (n:customer:supplier) 
WHERE exists(n.ID)
RETURN n.ID, n.nme
Izhaki
  • 23,372
  • 9
  • 69
  • 107
  • Thanks. AND label matching is return nothing. But we have data in both labels. I'm using neo4j 3.4.6 – user2848031 Aug 29 '18 at 13:49
  • The AND label matching means a node that has both the `customer` and `supplier` labels. Are you sure you have a node with both? Is this the correct case for the labels (Customer/Supplier maybe)? – Izhaki Aug 29 '18 at 13:55
  • I'm getting records when running (n.customer) only but with AND return nothing. – user2848031 Aug 29 '18 at 13:58
  • What does this return? `MATCH (n:customer:supplier) RETURN n` – Izhaki Aug 29 '18 at 14:06
  • It says "(no changes, no records)" – user2848031 Aug 29 '18 at 14:09
  • So you have no nodes with both these labels. – Izhaki Aug 29 '18 at 14:34
  • "MATCH (n:customer) return n " another query " MATCH (n:supplier) return n" return 100's of records – user2848031 Aug 29 '18 at 14:51
  • Yes. That means there are nodes with the label `customer` and there are nodes with the label `supplier`. But that doesn't mean that there is a node that has both these labels. You need the OR label matching. – Izhaki Aug 29 '18 at 15:00
0

The has() function has long since been deprecated and removed. Use exists() instead.

Also I'm not sure what you mean by combine 2 labels to get the data. The query as it is now will only match to nodes with both the :customer and :supplier label. Is that what you want?

InverseFalcon
  • 29,576
  • 4
  • 38
  • 51