Frage

Try it From Docs:

Code here:

SelectQuery<Record> selectQuery=Transaction.current().selectQuery();   
selectQuery.addSelect(Property.PROPERTY.PROPERTY_RSN);  
selectQuery.addFrom(Property.PROPERTY);  
SelectQuery<Record> selectUnionQuery=Transaction.current().selectQuery();  
selectUnionQuery.addSelect(Folder.FOLDER.FOLDER_RSN);  
selectUnionQuery.addFrom(Folder.FOLDER);  
selectQuery.union(selectUnionQuery);  
selectQuery.addOrderBy(Folder.FOLDER.FOLDER_RSN);  
selectQuery.fetch();  

Anyone can help me how can resolve this issue ?

Thanks

War es hilfreich?

Lösung

This question was recently asked on the jOOQ user group:

jOOQ's (historic) understanding of UNIONs is documented here:

This diverges from the SQL standard, where ORDER BY is applied to a whole set of subqueries. A fix for this is on the roadmap: https://github.com/jOOQ/jOOQ/issues/1658

In the mean time, you can work around this limitation by using a derived table:

ctx.select()
   .from(
      select(A)
     .from(T1)
     .union(
      select(B)
     .from(T2))
    )
   .orderBy(...)

Note that you may have to specify an alias for your derived table, in order to access its columns.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top