We currently have a problem displaying ordered objects with subqueries.
We have a table where we save the order of objects corresponding to their ranking. Now, if someone wants to see the actual objects themselves, we make the following query (query simplified and names changed):
from Object as object where object.id = some ( select objectid from RankingObject where type = :object_type ))
As we dont want to rank all the objects each time such a query is requested, we execute the ranking (and the creation of the RankingObjects) periodically and then just find the objects corresponding to the RankingObjects, which are ordered based on the ranking algorithm (highest ranking object is the first one in the table).
The subquery returns the objects in the correct order, just as they are saved in the database. The outer query returns the correct objects, but the order of them does not correspond to the inner query, but to the order of occurrence in the database (oldest objects appear first).
My question: How can we enforce the order of the inner query on the outer one? Of course, doing one query for each of the subquery items is no option performance-wise.