[MySQL] Query the first few records

Source: Internet
Author: User

From:http://www.cnblogs.com/xuxm2007/archive/2010/11/16/1878211.html

SELECT * FROM table LIMIT 5;

SELECT * FROM Issu_info limit 0,6

Limit 0,6
Here's the right one, showing the top 6.


SELECT * FROM Issu_info limit 7, 6;

Limit 7,6
Starting from 8th, take 6 strips


SELECT * FROM Table ORDER by rand () limit 1
This is a random selection of a record, if you want to extract more than 1 to change the number you want top

Using one of the features of the SELECT statement in MySQL makes it easy to implement the paging of the query results, the syntax of the SELECT statement:
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 amount of data returned by the SELECT statement, which has one or two parameters, and if two arguments are given,
The first parameter specifies the position of the first row returned in all data, starting with 0 (note that it is not 1), and the second parameter specifies a maximum number of rows to return
Number. For example:
SELECT * FROM Table LIMIT 5, 10; #返回第6-15 rows of data
SELECT * FROM table LIMIT 5; #返回前5行
SELECT * FROM table LIMIT 0, 5; #返回前5行


SQL queries the usage of the previous records in different databases 2008-03-30 am 10: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.postgres query before a few records SQL
SELECT * from TABLE LIMIT

Select ID from mytable ORDER by update_date desc limit 0,3;

[MySQL] Query the first few 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.