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

distinct;

Example

Schema for the following examples
#!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:

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

Remove duplicate answers that may result from using or patterns:

#!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.