---
schema_version: "1"
id: a3c72653e6042b754a5b1a026a4b4e4c12f52de2ac9d70f7044bd6c71d55eaf9
title: Label Expressions
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/data-cloud/data-cloud-query-guide/references/data-cloud-sql-reference/pgq/label-expressions.md
canonical_url: https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/label-expressions.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 5a4813da949c8479200bbf139fe6b4d3dcce251e945803767141cadc4dfbba8c
products:
  - Data 360 Query Guide
  - Data 360 Developer Documentation
---
# Label Expressions

**Applies to:** ✅ Data 360 SQL ✅ Tableau Hyper API

A label is the name you gave a vertex or edge in the graph definition, such as `individual` or `orderProduct`. A label expression lets you combine those names.

Write the expression after the colon: `(v:<label_expression>)` for an object, `-[e:<label_expression>]->` for a connection.

## Operators

| Operator | Name        | Meaning                 | Ecommerce example                |
| -------- | ----------- | ----------------------- | -------------------------------- |
| `:Label` | Label       | Has this label          | `(i:individual)`                 |
| `&`      | Conjunction | Has both labels         | `(i:individual & loyaltyMember)` |
| `\|`     | Disjunction | Has either label        | `(item:individual \| product)`   |
| `!`      | Negation    | Doesn't have this label | `(v:!loyaltyMember)`             |
| `%`      | Wildcard    | Any vertex or any edge  | `(item:%)`                       |

A bare `(v)` is the same as `(v:%)`.

Operators bind in this order: `!`, then `&`, then `|`. So `individual | product & featured` means `individual | (product & featured)`. And `!individual & product` means `(!individual) & product`. Use parentheses to override the default. To negate a negation, parenthesize the inner expression: `!(!individual)`.

```sql
WITH pg AS PROPERTY GRAPH (...)
SELECT * FROM GRAPH_TABLE(pg
    MATCH (item:(individual | product) & featured)
    COLUMNS (item.name)
) AS gt;
```

That matches a featured product, not a featured customer, unless you also gave customers the `featured` label.

## Extra Labels for These Examples

The commerce graph in [Defining a Property Graph](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/define-property-graph.md) has one label per table. Use this copy of that definition, with extra labels, for the examples on this page.

Don't put `loyaltyMember` on every customer if you want `individual & !loyaltyMember` to return rows. This definition uses a second Individual vertex table, `otherCustomers`, for customers who aren't loyalty members. Filter each Individual table so the same customer isn't in both, or every customer still matches `loyaltyMember` through `loyaltyCustomers`.

```sql
WITH pg AS PROPERTY GRAPH (
    VERTEX TABLES (
        (SELECT * FROM ssot__Individual__dlm WHERE ssot__Id__c IN ('I-100'))
            AS loyaltyCustomers KEY (ssot__Id__c)
            LABEL individual PROPERTIES (
                ssot__Id__c AS individualId,
                ssot__FirstName__c AS name
            )
            LABEL loyaltyMember,
        (SELECT * FROM ssot__Individual__dlm WHERE ssot__Id__c NOT IN ('I-100'))
            AS otherCustomers KEY (ssot__Id__c)
            LABEL individual PROPERTIES (
                ssot__Id__c AS individualId,
                ssot__FirstName__c AS name
            ),
        ssot__SalesOrder__dlm AS orders KEY (ssot__Id__c)
            LABEL salesOrder PROPERTIES (
                ssot__Id__c AS orderId,
                ssot__Name__c AS name
            ),
        ssot__GoodsProduct__dlm AS products KEY (ssot__Id__c)
            LABEL product PROPERTIES (
                ssot__Id__c AS productId,
                ssot__Name__c AS name
            )
            LABEL featured
            LABEL seasonal
    )
    EDGE TABLES (
        ssot__SalesOrder__dlm AS loyaltyOrders KEY (ssot__Id__c)
            SOURCE KEY (ssot__SoldToCustomerId__c) REFERENCES loyaltyCustomers
            DESTINATION KEY (ssot__Id__c) REFERENCES orders
            LABEL customerOrder PROPERTIES (
                ssot__CreatedDate__c AS createdDate
            ),
        ssot__SalesOrder__dlm AS otherOrders KEY (ssot__Id__c)
            SOURCE KEY (ssot__SoldToCustomerId__c) REFERENCES otherCustomers
            DESTINATION KEY (ssot__Id__c) REFERENCES orders
            LABEL customerOrder PROPERTIES (
                ssot__CreatedDate__c AS createdDate
            ),
        ssot__SalesOrderProduct__dlm AS orderProducts KEY (ssot__Id__c)
            SOURCE KEY (ssot__SalesOrderId__c) REFERENCES orders
            DESTINATION KEY (ssot__ProductId__c) REFERENCES products
            LABEL orderProduct
            LABEL promotionOrderProduct PROPERTIES (
                ssot__CreatedDate__c AS createdDate,
                ssot__OrderedQuantity__c AS quantity
            )
    )
)
```

The two Individual subqueries keep loyalty members and other customers in separate vertex tables. The two `customerOrder` edge tables give both groups a path to orders.

### Customers Who Are Loyalty Members

```sql
WITH pg AS PROPERTY GRAPH (...)
SELECT * FROM GRAPH_TABLE(pg
    MATCH (i:individual & loyaltyMember)
    COLUMNS (i.individualId, i.name)
) AS gt;
```

### Customers or Products

```sql
WITH pg AS PROPERTY GRAPH (...)
SELECT * FROM GRAPH_TABLE(pg
    MATCH (item:individual | product)
    COLUMNS (item.name)
) AS gt;
```

### Customers Who Aren't Loyalty Members

```sql
WITH pg AS PROPERTY GRAPH (...)
SELECT * FROM GRAPH_TABLE(pg
    MATCH (i:individual & !loyaltyMember)
    COLUMNS (i.name)
) AS gt;
```

### Regular or Promotion Line Items

```sql
WITH pg AS PROPERTY GRAPH (...)
SELECT * FROM GRAPH_TABLE(pg
    MATCH (i:individual)-[:customerOrder]->(:salesOrder)
        -[line:orderProduct | promotionOrderProduct]->(product:product)
    COLUMNS (i.individualId, product.productId, line.createdDate, line.quantity)
) AS gt;
```

```sql
WITH pg AS PROPERTY GRAPH (...)
SELECT * FROM GRAPH_TABLE(pg
    MATCH (i:individual)-[:customerOrder]->(:salesOrder)
        -[line:orderProduct & promotionOrderProduct]->(product:product)
    COLUMNS (i.individualId, product.productId, line.createdDate, line.quantity)
) AS gt;
```

### Featured or Seasonal Products

Using the same variable twice keeps only the records that match both patterns.

```sql
WITH pg AS PROPERTY GRAPH (...)
SELECT * FROM GRAPH_TABLE(pg
    MATCH (item:product), (item:featured | seasonal)
    COLUMNS (item.productId, item.name)
) AS gt;
```

That is the same as `MATCH (item:product & (featured | seasonal))`.

## Related Documentation

- [Querying with GRAPH_TABLE and MATCH](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/graph-table-match.md)
- [Cross-Label Property Access](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/cross-label-property-access.md)
- [Defining a Property Graph](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/define-property-graph.md)
