mysql select查询中使用limit的例子

发布时间:2019-11-11编辑:脚本学堂
分享一例mysql语句,在select查询中使用limit,有兴趣研究mysql中limit用法的朋友,可以作个参考。

本节内容:
mysql select查询中limit的用法

sql语句: 
 

复制代码 代码示例:

/*
mysql> select * from Product;
+-----------+------------+----------------------+-------+
| ProductID | Name       | Description          | Price |
+-----------+------------+----------------------+-------+
|         1 | Java       | Java Demo Code       |     6 |
|         2 | Swing      | Swing Demo Code      |     7 |
|         3 | C#         | C# Demo Code         |     4 |
|         4 | javascript | JavaScript Demo Code |     3 |
|         5 | SQL        | SQL Demo Code        |     8 |
|         6 | Struts     | Struts Demo Code     |     9 |
+-----------+------------+----------------------+-------+
6 rows in set (0.00 sec)

mysql> /* Browse Products */
mysql> SELECT ProductID, Name
    -> FROM Product
    -> ORDER BY ProductID
    -> LIMIT 3,4;
+-----------+------------+
| ProductID | Name       |
+-----------+------------+
|         4 | JavaScript |
|         5 | SQL        |
|         6 | Struts     |
+-----------+------------+
3 rows in set (0.00 sec)

*/
/* Create Database */ 
Drop TABLE Product;

CREATE TABLE Product (
    ProductID INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
    Name VARCHAR(50) NOT NULL,
    Description VARCHAR(255) NOT NULL,
    Price DECIMAL NULL
) Type=innodb;
 
 
/* Insert Data */
INSERT INTO Product (Name, Description, Price) VALUES ('Java',
                                                       'Java Demo Code',
                                                       5.99 );
INSERT INTO Product (Name, Description, Price) VALUES ('Swing',
                                                       'Swing Demo Code',
                                                       6.99 );
INSERT INTO Product (Name, Description, Price) VALUES ('C#',
                                                       'C# Demo Code',
                                                       3.99 );
INSERT INTO Product (Name, Description, Price) VALUES ('JavaScript',
                                                       'JavaScript Demo Code',
                                                       2.99 );
INSERT INTO Product (Name, Description, Price) VALUES ('SQL',
                                                       'SQL Demo Code',
                                                       7.99 );
INSERT INTO Product (Name, Description, Price) VALUES ('Struts',
                                                       'Struts Demo Code',
                                                       8.99 );
 

例子,使用limit查询:
 

复制代码 代码示例:

select * from Product;

/* Browse Products */
SELECT ProductID, Name
FROM Product
ORDER BY ProductID
LIMIT 3,4;