Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Wow. That's a complicated way to do something very simple. Try this:</p> <p>Assuming you have sequential ids (otherwise you could get no rows).</p> <pre><code>create view random_prova as select * from prova where id = (select min(id) from prova) + floor(RAND(0) * (select max(id) - min(id) from prova)); </code></pre> <p>This will give you 1 random row.</p> <p>To get multiple rows, either loop in a stored procedure or server program until you get enough rows, or programatically create a query that employs union. eg, this will give you 3 random rows:</p> <pre><code>select * from random_prova union select * from random_prova union select * from random_prova; </code></pre> <p>Note that using RAND(0) instead of RAND() means getting a different random number for each invocation. RAND() will give the same value for each invocation in the one statement (so using RAND() with union won't give you multiple rows).</p> <p>There are some shortcomings with using union - it is possible to get the same row twice by chance. Programatically calling this until you get enough rows is safer.</p> <p>To give better performance, use something like java to randomly select the ids for a simple query like </p> <pre><code>select * from prova where id in (...) </code></pre> <p>and have java (or perl or whatever) fill in the list with random ids - you would avoid the inefficiency of having to get the id range every time.</p> <p>Post if your ids are not sequential - there is an efficient way, but I its explanation is long. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload