selecting random rows from a table

11 views
Skip to first unread message

harryh

unread,
Sep 29, 2009, 3:20:35 PM9/29/09
to Lift
Let's say I want 10 random users from a table In SQL I would do this:

SELECT * FROM users ORDER BY random() LIMIT 10;

Is there any way (without resorting to a fully raw SQL query) to do
this with lift-mapper? I though this would work:

Users.findAll(OrderBySql("random()", IHaveValidatedThisSQL("harryh",
"2009-9-29")),
MaxRows(10))

This does not work, however, because when using SELECT DISTINCT you
can't ORDER BY something that you aren't selecting (in PostgreSQL at
least, might be ok in MySQL).

-harryh

Derek Chen-Becker

unread,
Sep 30, 2009, 8:21:13 AM9/30/09
to lif...@googlegroups.com
Hmmm. I have no idea how the distinct could possibly be getting in there since you're not using it as a QueryParam. Is that the exact code you're using for the findAll?

Derek
Reply all
Reply to author
Forward
0 new messages