SQL random query statement: [database usage tips] SQL statements generate random numbers. How to randomly display 20 records in the SQL query statement query data set and randomly retrieve the SQL statements of several records, you can use the SQL statement to obtain a random number as follows: SQLServer: SelectTOPN * FromTABLEorderByNewID () Access: dimrr
SQL random query statement: [database usage tips] SQL statements generate random numbers. How to randomly display 20 records in the SQL query statement query data set and randomly retrieve the SQL statements of several records, the following describes how to use an SQL statement to obtain a random number: SQL Server: Select TOP N * From TABLE order By NewID () Access: dim r
SQL random query statements: [database usage tips] SQL statements generate random numbers. How to randomly display 20 records in the SQL query statement query data set and randomly retrieve SQL statements with several records, how to use SQL statements to obtain random numbers
The method is as follows:
SQL Server:
Select top n * From TABLE order By NewID ()
Access:
Dim r
Randomize
R = rnd
SQL = "select top 10 * from table order by rnd (" & r & "-id )"
In rnd ("& r &"-id), the id is an automatic number field, which can be completed using any other value, such as UserName)
Select top 10 * from table order by rnd ("& r &"-Len (UserName ))
MySql:
Select * From TABLE order By Rand () Limit 10
OrACLE:
Select * from (select * from t order by dbms_random.value) where rownum <10