# `links` statement

The statement `<RELATION VAR> links (<ROLE>: <PLAYER VAR> [ , …​ ])` is used to identify the `<PLAYER VAR>` as playing `<ROLE>` in the `<RELATION VAR>`.

Schema for the following examples

```typeql
#!test[schema, commit]
define
relation friendship, relates friend @card(0..2);
entity user, plays friendship:friend;
```

## [](#_inserting_a_role_player)Inserting a role player

The `links` keyword can be used to attach a role player to a relation instance.

```typeql
#!test[write]
#{{
match $person isa user; $friendship isa friendship;
#}}
insert $friendship links (friend: $person);
```

Multiple role players can be attached in the same statement.

```typeql
#!test[write]
#{{
match $alice isa user; $bob isa user; $friendship isa friendship;
#}}
insert $friendship links (friend: $alice, friend: $bob);
```

## [](#_deleting_a_role_player)Deleting a role player

The `links` keyword is used to remove a role player from a relation instance.

```typeql
#!test[write]
#{{
match $friendship isa friendship, links ($person);
#}}
delete links ($person) of $friendship;
```

Multiple role players can be removed in the same statement.

```typeql
#!test[write]
#{{
match $friendship isa friendship, links (friend: $alice, friend: $bob);
#}}
delete links ($alice, $bob) of $friendship;
```

## [](#_matching_role_players)Matching role players

The `links` keyword can be used to match relations along with their role players.

```typeql
#!test[read]
match $friendship links (friend: $person);
```

The role specifiers may be variables as well.

```typeql
#!test[read]
match $friendship links ($role: $person);
```

Note that the role label is not required.

```typeql
#!test[read]
match $friendship links ($person);
```

If a relation binding is not required, the relation type shorthand can be used directly instead.

```typeql
#!test[read]
match friendship ($alice, $bob);
```

[isa](../isa/index.md) [has](../has/index.md)

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