Select distinct

I have this graph:

let $a1 = create vertex set name = 'a1';
let $a2 = create vertex set name = 'a2';
let $v1 = create vertex set name = 'v1';
let $v2 = create vertex set name = 'v2';
let $v3 = create vertex set name = 'v3';
create edge from $a1 to $v1;
create edge from $a1 to $v2;
create edge from $a2 to $v2;
create edge from $a2 to $v3;

Visually:

Captura%20de%20pantalla%20de%202019-10-08%2011-55-03

If I have this query:

select expand($c)
let $a = (select expand(out()) from #{a1rid}),
    $b = (select expand(out()) from #{a2rid}),
    $c = unionall($a, $b)
)

the resultset is v1, v2, v2, v3. Now:

  1. Why I must expand $c if the nodes are already expanded in $a and $b?

  2. I want the resultset without duplicates but I can’t figure out how.

The next query keeps bringing duplicates:

select expand(*) from (
    select distinct $c
    let $a = (select expand(out()) from #{a1rid}),
        $b = (select expand(out()) from #{a2rid}),
        $c = unionall($a, $b))

select distinct $c does not work, or I don’t know how to use it. I’m using OrientDB 3.0.23.

Hi @johny65

The following should do the trick:

select expand(set($c))
let $a = (select expand(out()) from #9:0),
    $b = (select expand(out()) from #10:0),
    $c = unionall($a, $b)

about your other question you have to expand $c because the unionAll() returns a collection as a single value, not a result set

Thanks

Luigi

1 Like

Thank you very much @luigidellaquila.