# Distinct operator

The distinct operator removes duplicate elements from the data stream. Elements are considered duplicates if all their variables have the same values.

## [](#_syntax)Syntax

```typeql
distinct;
```

## [](#_example)Example

Schema for the following examples

```typeql
#!test[schema, commit]
define
  entity content owns id;
  entity page sub content,
    owns page-id,
    owns name;
  entity profile sub page,
    owns username;
  entity user sub profile,
    owns phone,
    owns karma;

  attribute id value string;
  attribute page-id sub id;
  attribute username sub page-id;
  attribute name value string;
  attribute phone value string;
  attribute karma value double;
```

Find all unique names of users:

```typeql
#!test[read]
match
  $user isa user, has name $name;
select $name;
distinct;
```

Remove duplicate answers that may result from using `or` patterns:

```typeql
#!test[read]
match
  { $p isa user; } or { $p has name "John"; };
distinct; # Make sure that the person with name John is returned at most once.
```

[Require](../require/index.md) [Sort](../sort/index.md)

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