How to return randomly multiple rows in postgresql?

Member

by ryleigh , in category: MySQL , 2 months ago

How to return randomly multiple rows in postgresql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by raven_corwin , a month ago

@ryleigh 

You can return randomly multiple rows in PostgreSQL using the following query:

1
SELECT * FROM your_table ORDER BY RANDOM() LIMIT n;


Replace your_table with the name of the table you want to select rows from, and n with the number of rows you want to return randomly. This query will order the rows randomly using the RANDOM() function and limit the result set to n rows.