Select where version = max (), How would this be done?

31 views
Skip to first unread message

Aceitunas y encurtidos Quijote

unread,
Nov 25, 2016, 3:48:53 AM11/25/16
to orient-...@googlegroups.com
Hi, I want to retrieve the latest version of each Composition object.

select from CompositionVersions where version = (select max(version) from CompositionVersions)

But this not working.

1-Is there another more efficient way to recover the latest version, without knowing the number of versions that there are?
2-Would it be convenient to save in the Composition object, an attribute with the id of the latest version?
 
lastVersion.png

Aceitunas y encurtidos Quijote

unread,
Nov 25, 2016, 8:54:53 AM11/25/16
to OrientDB
I've tried this but it does not work either.

SELECT FROM CompositionVersions LET 
$temp = (select max(version) from CompositionVersions)
WHERE $temp = version 

Oleksandr Gubchenko

unread,
Nov 25, 2016, 4:14:54 PM11/25/16
to OrientDB
Maybe you should use @version

Aceitunas y encurtidos Quijote

unread,
Nov 28, 2016, 2:58:18 AM11/28/16
to OrientDB
Hi, I do not understand, could you give an example?
The version property of my object is not @version

Aceitunas y encurtidos Quijote

unread,
Nov 28, 2016, 4:41:51 AM11/28/16
to orient-...@googlegroups.com
I am trying with this query and it does not return anything:
select * from CompositionVersions where value.uid.value.split("::")[2] = (select max(value.uid.value.split("::")[2] ) from CompositionVersions)


This return the number 4:
select max(value.uid.value.split("::")[2] ) from CompositionVersions

This yes returns results
select * from CompositionVersions where value.uid.value.split("::")[2] = 4 



El viernes, 25 de noviembre de 2016, 9:48:53 (UTC+1), Aceitunas y encurtidos Quijote escribió:

Aceitunas y encurtidos Quijote

unread,
Nov 28, 2016, 5:05:44 AM11/28/16
to OrientDB
I have tried again with this query and now if it works:

select * from CompositionVersions where value.uid.value.split("::")[2] in (select max(value.uid.value.split("::")[2] ) from CompositionVersions)

it is right?


El viernes, 25 de noviembre de 2016, 9:48:53 (UTC+1), Aceitunas y encurtidos Quijote escribió:
Reply all
Reply to author
Forward
0 new messages