Randomly pick rows from table

Moderator: NorbertKrupa

Post Reply
dbmsuser7
Intermediate
Intermediate
Posts: 71
Joined: Tue Jan 28, 2014 3:03 am

Randomly pick rows from table

Post by dbmsuser7 » Mon Apr 14, 2014 6:56 pm

How can one randomly pick rows from a table?

A stackoverflow thread (http://stackoverflow.com/questions/5806 ... ows-in-sql) suggests

Code: Select all

SELECT column FROM table
ORDER BY RANDOM()
LIMIT 1
in the case of one row, for PostgreSQL. The same code seems to work in Vertica, though I don't have the time to try to verify it by looking at tests of randomness. ;)

Anyone have a problem with this code snippet?

id10t
GURU
GURU
Posts: 732
Joined: Mon Apr 16, 2012 2:44 pm

Re: Randomly pick rows from table

Post by id10t » Tue Apr 15, 2014 9:27 am

Hi!

[DELETED]
Last edited by id10t on Wed May 06, 2015 5:35 pm, edited 1 time in total.

dbmsuser7
Intermediate
Intermediate
Posts: 71
Joined: Tue Jan 28, 2014 3:03 am

Re: Randomly pick rows from table

Post by dbmsuser7 » Tue Apr 15, 2014 2:44 pm

sKwa wrote: I have no, but book Sql Antipatterns does.
OK...seems like what he didn't like about it was that it doesn't scale well. I'm only doing some spot-checking, so scaling isn't really a concern for me.
sKwa wrote: May be this thread will interest you too:
Selecting a Random Set of Rows from a Table
I'll check that out.

Post Reply

Return to “Vertica SQL”