Order by Rand?

613 views
Skip to first unread message

Ryan Cornia

unread,
Aug 22, 2013, 3:35:55 PM8/22/13
to jooq...@googlegroups.com
I've been converting an SQL app to use JOOQ. So far, it has worked great, but I have 2 final queries that do a random order on the records.

What is the JOOQ way of doing it without resorting to raw SQL? In raw SQL, I do "order by new_id()", by was hoping for .order(RAND), but that doesn't work.

Thanks, great library!

Lukas Eder

unread,
Aug 23, 2013, 5:36:09 AM8/23/13
to jooq...@googlegroups.com

2013/8/22 Ryan Cornia <ryanc...@gmail.com>

I've been converting an SQL app to use JOOQ. So far, it has worked great, but I have 2 final queries that do a random order on the records.

What is the JOOQ way of doing it without resorting to raw SQL? In raw SQL, I do "order by new_id()", by was hoping for .order(RAND), but that doesn't work.

How doesn't it work? Have you seen the DSL.rand() function?
http://www.jooq.org/javadoc/latest/org/jooq/impl/DSL.html#rand()

Of course, plain SQL isn't a bad choice in this case either, if you prefer using new_id():
    orderBy(DSL.field("new_id()"))
Reply all
Reply to author
Forward
0 new messages