Hi Venkat,

jOOQ's (historic) understanding of UNIONs is documented here:
http://www.jooq.org/doc/3.2/manual/sql-building/sql-statements/select-statement/union-clause/#N10EC1

This diverges from the SQL standard, where ORDER BY is applied to a whole
set of subqueries. A fix for this is scheduled for jOOQ 3.3:
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))

     .asTable()

    )

   .orderBy(...)


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

Hope this helps,
Lukas

2013/12/6 Venkat Sadasivam <[email protected]>

> We want to write a union query combining 3 SELECT  and have a single order
> by clause. Is it possible do with jOOQ? If so can we get an example?
>
> --
> You received this message because you are subscribed to the Google Groups
> "jOOQ User Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to