Unlock the Power of AI

1 million free tokens

88% Price Reduction

Activate Now

Multi-label query

Updated at: 2025-02-13 11:47

Labels are used to represent the properties of nodes and edges. You can categorize the nodes and edges based on the semantic meaning of properties.

Specify multiple labels in a statement

Separate multiple labels by using | as shown in the following sample code:

(n:Person|Company)
[p:KNOWS|LIKES]

Prepare test data

SELECT create_graph('imdb');
SELECT *
FROM cypher('imdb', $$
 CREATE (toby:actor {name: 'Toby Maguire'}),
  (willam:director {name: 'Willam Dafoe'}),
  (hanks:person {name: 'Tom Hanks'}),
  (spiderman:movie {title: 'Spiderman'}),
  (toby)-[:acted_in]->(spiderman),
  (willam)-[:directed]->(spiderman),
  (hanks)-[:likes]->(spiderman)
$$) AS (a agtype);

Examples

  • Query the names with either the actor or director label.

    SELECT * FROM cypher('imdb', $$
    MATCH (a:actor|director) 
    RETURN a.name
    $$
    ) as (name agtype);

    Sample result:

          name      
    ----------------
     "Toby Maguire"
     "Willam Dafoe"
    (2 rows)
  • Query the individuals who are related to the movie Spiderman in either the directed or acted_in relationship.

    SELECT * FROM cypher('imdb', $$
    MATCH (p)-[r:acted_in|directed]->(:movie {title: 'Spiderman'}) 
    RETURN p.name
    $$
    ) as (name agtype);

    Sample result:

          name      
    ----------------
     "Toby Maguire"
     "Willam Dafoe"
    (2 rows)
  • On this page (1, T)
  • Specify multiple labels in a statement
  • Prepare test data
  • Examples
Feedback
phone Contact Us

Chat now with Alibaba Cloud Customer Service to assist you in finding the right products and services to meet your needs.

alicare alicarealicarealicare