This article describes how to use SQL statements to randomly retrieve data from a database table _ MySQL details. For more information, see
-- Random acquisition of 10 data records
SQL Server: SELECT TOP 10 * FROM T_USER ORDER BY NEWID () ORACLE: SELECT * FROM (SELECT * FROM T_USER ORDER BY DBMS_RANDOM.RANDOM () WHERE RONUM <= 10 MySQL: SELECT * FROM T_USER order by rand () LIMIT 10 Access: select top 10 * FROM T_USER order by rnd ([an automatic number field])
This statement can run in the "query" in Access and obtain random results, but it cannot get the expected random effect in the background program code such as ASP. NET.
The correct syntax is as follows:
Take ASP. NET as an example:
Random random = new Random (System. guid. newGuid (). getHashCode (); int r = random. next (); string SQL = "SELECT TOP 10 * FROM T_USER ORDER BY RND (" + (-r) + "* automatically numbered field )"
The preceding section uses SQL statements to randomly retrieve data from a table in the database _ MySQL. For more information, see The PHP Chinese website (www.php1.cn )!