Search code examples
orientdb

Display the query if the number of equal vertex is at least 1 (let blocks)


I actually have this query but it doesn't work :

SELECT expand($Result)
let $Cri = (
  SELECT *
  FROM Cri
  WHERE libelle = "abbaye"
),
$Ontologie = (
  SELECT *
  FROM Ontologie
  WHERE libelle = "BlocModal_3_VISITE"
),
$Result = (
  SELECT *
  FROM $Ontologie
  WHERE $Cri.out().@rid = $Ontologie.out().out().out("Pertinent").@rid
)

First, When I execute in differents query :

$Ontologie.out().out().out("Pertinent")

$Cri.out()

I find the same result so I don't understand why it doesn't work in the let block

Secondly, for the $Result, I want to select every $Ontologie if I have at least one time this expression true :

 $Cri.out().@rid = $Ontologie.out().out().("Pertinent").@rid 

Finally, I know I can't do a WHERE clause because it'll only select the $Ontologie that match with this expression.

I actually have tried with 'IF' but it seems to doesn't work..

Here is my Schema : enter image description here

Thanks in advance.


Solution

  • The result of a let is a list and therefore you don't must use = but contains

    You could use

    SELECT expand($Result)
    let $Cri = ( SELECT * FROM Cri WHERE libelle = "abbaye"),
    $Ontologie = ( SELECT * FROM Ontologie WHERE libelle = "BlocModal_3_VISITE"),
    $Result = ( SELECT * FROM $Ontologie WHERE $Cri.out().@rid contains out().out().out().@rid)
    

    Hope it helps