Green Zhukovsky Green Zhukovsky - 8 months ago 56
SQL Question

OrientDB - filter selected vertices by other vertices connected to them

I'm not an OrientDB profi, so maybe my question will sound dumb; but I didn't find any answers in docs or on the Net.

This is a sample of a data structure that I have:
I want to find all of the beavers, that have blue eyes, and they're happy and they know it.

I do manage to select the eye color and the happiness state with out() function - something like

SELECT out('has').eyeColors, out('is').happinessState FROM beavers

But how do I filter by those connected vertices? I've tried

SELECT * FROM beavers WHERE out('has').eyeColors = 'blue' AND out('is').happinessState = 'happy and knows it'


SELECT * FROM beavers WHERE (SELECT out('has').eyeColors FROM beavers) = 'blue' AND (SELECT out('is').happinessState FROM beavers) = 'happy and knows it'

but both of the query types tend to return empty results.

So - how can I achieve such a selection?

*I run Community Edition, v. 2.1.11, and do all of this in server-side JS function.



in the WHERE condition you need to use the CONTAINS word because the out() - so for in() and both() - returns a list.


select from Beaver where out('has').eyeColors contains "Blue" and out("iss").happinessState contains "happy and knows it"

You can verify whether it returns a list or not by selecting it:

select out('has').eyeColors from Beaver


I see that you're using an edge class called is that, I think, it's not allowed since it is a private word.

Hope it helps. Ivan


select name from Children
let $a=(select from Beaver where in('has').@rid contains $parent.$current.@rid and out('has').eyeColor contains "Blue" and out("iss").happinessState contains "happy and knows it")
where $a.size() > 0