# `sub` statement

The statement `<LABEL> sub <SUPERTYPE LABEL>` is used to identify the `<LABEL>` type as a subtype of `<SUPERTYPE LABEL>`.

Schema for the following examples

```typeql
#!test[schema]
define entity profile; entity user;
```

## [](#_defining_subtyping)Defining subtyping

The `sub` keyword can be used to define a type as a subtype of another type.

```typeql
#!test[schema]
define user sub profile;
```

## [](#_undefining_subtyping)Undefining subtyping

The `sub` keyword can be used to undefine a type’s subtyping of a type.

```typeql
#!test[schema]
undefine sub profile from user;
```

## [](#_matching)Matching

### [](#_matching_supertypes)Matching supertypes

The `sub` keyword can be used to match all supertypes of a type. This will result in all the transitive supertypes, including supertypes of its supertype.

```typeql
#!test[read]
match user sub $t;
```

Example TypeDB Console output

   --------
    $t | type content
   --------
    $t | type page
   --------
    $t | type profile
   --------
    $t | type user
   --------

#### [](#_matching_declared_supertypes)Matching declared supertypes

The `sub!` keyword can be used to match only a declared supertype of a type. This will result in only the types with defined `sub` statements, excluding the subtypes of these types.

```typeql
#!test[read]
match user sub! $t;
```

Example TypeDB Console output

   --------
    $t | type profile
   --------

### [](#_matching_subtypes)Matching subtypes

The `sub` keyword can be used to match all subtypes of a `<SUPERTYPE LABEL>`. This will result in all the transitive subtypes, including subtypes of its subtypes.

```typeql
#!test[read]
match $t sub profile;
```

Example TypeDB Console output

   --------
    $t | type profile
   --------
    $t | type user
   --------
    $t | type organization
   --------
    $t | type company
   --------
    $t | type charity
   --------
    $t | type educational-institute
   --------
    $t | type school
   --------
    $t | type college
   --------
    $t | type university
   --------

#### [](#_matching_declared_subtypes)Matching declared subtypes

The `sub!` keyword can be used to match only declared subtypes of a type. This will result in only the types with defined `sub` statements, excluding the subtypes of these types.

```typeql
#!test[read]
match $t sub! profile;
```

Example TypeDB Console output

   --------
   $t | type user
   --------
   $t | type organization
   --------

[attribute](../attribute/index.md) [relates](../relates/index.md)

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