MySQL: Select * from tablename Order by rand () limited 10sqlserver: select top 10 * from tablename Order by newid ()
Oracle: A method using dbms random value
SQL> SELECT * FROM (Select * from t order by dbms_random.value) Where rownum <10;
A ---------- 39 101 134 5 83 97 96 140 81
9 lines have been selected.
SQL> SELECT * FROM (Select * from t order by dbms_random.value) Where rownum <10;
A ---------- 27 118 141 103 128 10 142 68 74 Some people say this is the worst method, please inform us better solution!
Access (1):
Yourstr = "* 1 * 3 * 4 * 6 * 12 * ...."
SQL = "SELECT TOP 10 * FORM YOURDB WHERE INSTR ('*' & id & '*', '" & yourstr & ") <> 0
Access (2):
<%
N = 10 '' takes any 10 records
SET RS = Server.createObject ("AdoDb.Recordset")
SQL = "SELECT * from Table"
RS.Open SQL, CONN, 1, 1
Count = rs.Recordcount '' record total
If count <> EMPTY THEN
Randomize
FOR i = 1 to n '' cycle N times
Num = FIX (RND * Count) 'Num is a number of randomly generated record lines, using fix () so that it will not be greater than Count values.
Rs.Move Num '' Move to change
Response.write RS (0) '' Out of this record
rs.movefirst '' Don't forget to move the pointer to the first
NEXT
END IF
Rs.close
SET RS = Nothing
%>
SQL> SELECT * FROM (Select * from t order by dbms_random.value) Where rownum <10;
A ---------- 39 101 134 5 83 97 96 140 81
9 lines have been selected.
SQL> SELECT * FROM (Select * from t order by dbms_random.value) Where rownum <10;
A ---------- 27 118 141 103 128 10 142 68 74 Some people say this is an efficient way to inform this better solution! Access (1):
Yourstr = "* 1 * 3 * 4 * 6 * 12 * ...."
SQL = "SELECT TOP 10 * FORM YOURDB WHERE INSTR ('*' & id & '*', '" & yourstr & ") <> 0
Access (2):
<%
N = 10 '' takes any 10 records
SET RS = Server.createObject ("AdoDb.Recordset")
SQL = "SELECT * from Table"
RS.Open SQL, CONN, 1, 1
Count = rs.Recordcount '' record total
If count <> EMPTY THEN
Randomize
FOR i = 1 to n '' cycle N times
Num = FIX (RND * Count) 'Num is a number of randomly generated record lines, using fix () so that it will not be greater than Count values.
Rs.Move Num '' Move to change
Response.write RS (0) '' Out of this record
rs.movefirst '' Don't forget to move the pointer to the first
NEXT
END IF
Rs.close
SET RS = Nothing
%>