# `relates` statement

The statement `<RELATION LABEL> relates <LABEL>` is used to identify the `<LABEL>` as a role type related by `<RELATION LABEL>`.

It can be extended to `<RELATION LABEL> relates <LABEL> as <SPECIALIZED LABEL>` to specify specialization between two role types. `SPECIALIZED LABEL>` should be inherited by `<RELATION LABEL>` from a supertype. `<LABEL>` becomes a subtype of `<SPECIALIZED LABEL>`, and the `<RELATION LABEL>` instances do no longer accept role players of `<SPECIALIZED LABEL>`. `<LABEL>` is called **specializing relates**, and `<SPECIALIZED LABEL>` is called **specialized relates**.

Schema for the following examples

```typeql
#!test[schema, commit]
define
  relation parentship, relates child;
  relation fathership sub parentship;
```

## [](#_defining_role_types)Defining role types

The `relates` keyword can be used to define a role type for a relation type.

```typeql
#!test[schema]
define parentship relates parent;
```

### [](#_defining_specializing_role_types)Defining specializing role types

The `relates …​ as` construction can be used to define a role type specializing an inherited role type.

```typeql
#!test[schema, commit]
define fathership relates father as parent;
```

### [](#_redefining_specializing_role_types)Redefining specializing role types

The `relates …​ as` construction can be used to define a role type specializing an inherited role type.

```typeql
#!test[schema, rollback]
redefine fathership relates father as child;
```

## [](#_undefining_role_types)Undefining role types

The `relates` keyword can be used to undefine a role type from a relation.

```typeql
#!test[schema, rollback]
#{{
undefine as parent from fathership relates father;
#}}
#---
undefine relates parent from parentship;
```

### [](#_undefining_role_types_specialization)Undefining role types specialization

The `relates …​ as` construction can be used to undefine a role type specialization.

```typeql
#!test[schema, rollback]
undefine as parent from fathership relates father;
```

## [](#_matching)Matching

### [](#_matching_related_role_types)Matching related role types

The `relates` keyword can be used to match all role types related by a relation type.

```typeql
#!test[schema]
match parentship relates $r;
```

### [](#_matching_relation_types)Matching relation types

The `relates` keyword can be used to match all relation types for a role type with a label `<LABEL>`.

```typeql
#!test[schema]
match $r relates parent;
```

Note that a scope can be used to have more specific results. The previous query can return results for different role types with the same `<LABEL>`, while the following example returns only relation types with the specified scope.

```typeql
match $r relates parentship:parent;
```

[sub](../sub/index.md) [plays](../plays/index.md)

[Edit on GitHub](https://github.com/typedb/typedb-docs/edit/3.x-development/typeql-reference/modules/ROOT/pages/statements/relates.adoc) Edit this page on GitHub.