Please take a look at the following table and data:
My requirement is to select two rows randomly from the above data set. How can i to this by using a query.Code:value ----- oracle mysql postgres netezza mangodb
Use the DBMS_RANDOM package to get random values.
Query using rownum:
Code:select * from ( select value from tablename order by DBMS_RANDOM.RANDOM ) a where rownum <= 2;
Query using row number analytic function
Code:select value from ( select value, row_number() over(order by DBMS_RANDOM.RANDOM) r from tablename ) a where r <= 2;