Frank Provost Frank Provost - 5 months ago 13x
SQL Question

orientDB : Only show results / return something if a min of datasets is available

I've built a query generator to generate subquerys on which I can access specific data which is related to the user, but does not contain the user information directly.

user->user_has_profiles->profile The query will return profiles for example.

Since one user can have multiple profiles the amount of results of this query might be amount_of_users * 0-n

I'd like to only return results if at least 5 users where involved in my query.

I found this for sqlite / mysql SQL syntax: select only if more than X results but since neither join nor having is available for orientDB I'm interested if there is any solution for this.

Example part of the query

select expand(rid) from (
select person_id, last(rid) as rid from (
select in('person_owns_profile').person_id[0] as person_id, @rid as rid, valid_from from (
select from (


I tried with these records.

enter image description here

This is the graph.

enter image description here

I used this query

select from (select from profile)
let $b= (select count(*) from user)
where $b[0].count>5

enter image description here enter image description here

Hope it helps.


You can use also this query

select from (select from profile) where "true" in (select if(eval(" count > 2"), "true", "false") from (select count(*) from user))