Use SQL statements to randomly retrieve data from a database table _ MySQL

Source: Internet
Author: User
Tags how to use sql
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 )!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.