MySQL queries the first few records

Source: Internet
Author: User

Select * from Table limit 5;

Select * From issu_info limit 0, 6

Limit 0, 6
This is correct. The first six items are displayed.


Select * From issu_info limit 7, 6;

Limit 7, 6
Take from 8th, take 6


Select * from Table order by rand () limit 1
This is to randomly select a record. If you want to extract multiple records, change 1 to the number you want to top.

Using a feature of the SELECT statement in MySQL, you can easily implement paging of query results. The syntax of the SELECT statement is as follows:
Select [straight_join] [SQL _small_result] [SQL _big_result] [high_priority]
[Distinct | distinctrow | all]
Select_expression ,...
[Into OUTFILE 'file _ name' export_options]
[From table_references
[Where where_definition]
[Group by col_name,...]
[Having where_definition]
[Order by {unsigned_integer | col_name | formula} [ASC | DESC],...]
[Limit [offset,] rows]
[Procedure procedure_name]
The limit clause can be used to limit the number of data returned by the SELECT statement. It has one or two parameters. If two parameters are provided,
The first parameter specifies the position of the first row returned in all data, starting from 0 (note not 1). The second parameter specifies the maximum number of returned rows.
Number. For example:
Select * from Table limit 5, 10; # return data in rows 6-15
Select * from Table limit 5; # Return the first five rows
Select * from Table limit; # Return the first five rows


SQL statements used to query the first few records in different databases: 261. Oracle
Select * From Table1 where rownum <= N


2. Informix
Select first N * From Table1


3. DB2
Select * row_number () over (order by col1 DESC) as rownum where rownum <= N
Or
Select column from Table fetch first n rows only


4. SQL Server
Select Top N * From Table1


5. Sybase
Set rowcount n
Go
Select * From Table1


6. MySQL
Select * From Table1 limit n


7. FoxPro
Select * Top N from Table order by Column

8. query the first few SQL records in Postgres
Select * from Table limit

Select ID from mytable order by update_date DESC limit 0, 3;

Related Article

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.