MySQL SELECT LIMIT

Source: Internet
Author: User
Tags mysql commands

MySQL select limit specifies the number of rows to query MySQL, which is the most widely used database. It is known for its lightweight, open-source, and efficient nature. Once a product owned by SUN, as SUN was acquired by Oracle, MySQL was also transferred to Oracle. Compared with Microsoft's ms SQL Server, Oracle and MySQL have many advantages and features. MySQL provides a simpler and clearer way to query the specified number of rows than other databases. When we use the select function to query data, what if we want to return the first few or several intermediate results? It's easy to add the limit constraint at the end of the statement. LIMIT (case insensitive, because MySQL commands are case insensitive) constraints are used to LIMIT the number of rows returned by a SELECT statement. LIMIT can be followed by one or two Integer constants, if there are two integers, the first integer is used to specify the offset of the first returned result, and the second integer is used to specify the maximum number of returned results. However, it is worth noting that the offset of the first result is 0 (instead of 1). If you only care about the first result, you can use the following statement.

[SQL] select * from table limit 0, 1;

 

If LIMIT is only followed by an integer n, only the first n records are searched. Therefore, limit n is equivalent to limit 0, n.
[SQL] select * from table limit 7,100; // search records row 8-100 select * from table limit 7,-1; // select * from table limit 7 from row 8 to last line of the record; // select * from table limit for the first 7 rows of the record; // equivalent to the previous command, search for the first seven rows of records

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.