• MySQL之limit使用


    如emp表,

    复制代码
    mysql> select * from emp;
    
    +-----+--------+-----+--------+--------+----------+---------------------+---------------------+
    | eid | ename  | sex | salary | deptid | leaderid | birdate             | income              |
    +-----+--------+-----+--------+--------+----------+---------------------+---------------------+
    |   1 | 马云   | 男  |      1 |   1000 |        0 | 1985-03-05 00:00:00 | 2008-05-06 00:00:00 |
    |   2 | 李小龙 | 男  |  20000 |   1001 |        1 | 1983-06-07 00:00:00 | 2012-05-05 00:00:00 |
    |   3 | 成龙   | 男  |  23000 |   1002 |        2 | 1973-06-07 00:00:00 | 2013-05-05 00:00:00 |
    |   4 | 杨明   | 男  |  22000 |   1003 |        2 | 1993-06-09 00:00:00 | 2013-05-06 00:00:00 |
    |   5 | 黎明   | 男  |  28000 |   1004 |        3 | 1992-08-09 00:00:00 | 2013-07-06 00:00:00 |
    |   6 | 范冰冰 | 女  |  12000 |   1005 |        4 | 1994-08-09 00:00:00 | 2014-07-06 00:00:00 |
    |   7 | 刘亦菲 | 女  |  19000 |   1006 |        5 | 1997-08-09 00:00:00 | 2011-07-03 00:00:00 |
    |   8 | 唐嫣   | 女  |  39000 |   1007 |        6 | 1991-08-09 00:00:00 | 2015-07-03 00:00:00 |
    +-----+--------+-----+--------+--------+----------+---------------------+---------------------+
    复制代码

    拿表中 1 条数据

    mysql> select * from emp limit 1;
    +-----+-------+-----+--------+--------+----------+---------------------+---------------------+
    | eid | ename | sex | salary | deptid | leaderid | birdate             | income              |
    +-----+-------+-----+--------+--------+----------+---------------------+---------------------+
    |   1 | 马云  | 男  |      1 |   1000 |        0 | 1985-03-05 00:00:00 | 2008-05-06 00:00:00 |
    +-----+-------+-----+--------+--------+----------+---------------------+---------------------+

    或者

    复制代码
    mysql> select * from emp limit 0,1
    ;
    +-----+-------+-----+--------+--------+----------+---------------------+---------------------+
    | eid | ename | sex | salary | deptid | leaderid | birdate             | income              |
    +-----+-------+-----+--------+--------+----------+---------------------+---------------------+
    |   1 | 马云  | 男  |      1 |   1000 |        0 | 1985-03-05 00:00:00 | 2008-05-06 00:00:00 |
    +-----+-------+-----+--------+--------+----------+---------------------+---------------------+
    
    
    mysql> select * from emp limit 1,1
    ;
    +-----+--------+-----+--------+--------+----------+---------------------+---------------------+
    | eid | ename  | sex | salary | deptid | leaderid | birdate             | income              |
    +-----+--------+-----+--------+--------+----------+---------------------+---------------------+
    |   2 | 李小龙 | 男  |  20000 |   1001 |        1 | 1983-06-07 00:00:00 | 2012-05-05 00:00:00 |
    +-----+--------+-----+--------+--------+----------+---------------------+---------------------+
    复制代码

    拿其中3条数据

    复制代码
    mysql> select * from emp limit 2,3;
    +-----+-------+-----+--------+--------+----------+---------------------+---------------------+
    | eid | ename | sex | salary | deptid | leaderid | birdate             | income              |
    +-----+-------+-----+--------+--------+----------+---------------------+---------------------+
    |   3 | 成龙  | 男  |  23000 |   1002 |        2 | 1973-06-07 00:00:00 | 2013-05-05 00:00:00 |
    |   4 | 杨明  | 男  |  22000 |   1003 |        2 | 1993-06-09 00:00:00 | 2013-05-06 00:00:00 |
    |   5 | 黎明  | 男  |  28000 |   1004 |        3 | 1992-08-09 00:00:00 | 2013-07-06 00:00:00 |
    +-----+-------+-----+--------+--------+----------+---------------------+---------------------+
    复制代码

    拿其中4条数据

    复制代码
    mysql> select * from emp limit 2,4;
    +-----+--------+-----+--------+--------+----------+---------------------+---------------------+
    | eid | ename  | sex | salary | deptid | leaderid | birdate             | income              |
    +-----+--------+-----+--------+--------+----------+---------------------+---------------------+
    |   3 | 成龙   | 男  |  23000 |   1002 |        2 | 1973-06-07 00:00:00 | 2013-05-05 00:00:00 |
    |   4 | 杨明   | 男  |  22000 |   1003 |        2 | 1993-06-09 00:00:00 | 2013-05-06 00:00:00 |
    |   5 | 黎明   | 男  |  28000 |   1004 |        3 | 1992-08-09 00:00:00 | 2013-07-06 00:00:00 |
    |   6 | 范冰冰 | 女  |  12000 |   1005 |        4 | 1994-08-09 00:00:00 | 2014-07-06 00:00:00 |
    +-----+--------+-----+--------+--------+----------+---------------------+---------------------+
    复制代码

    拿 5条数据

    复制代码
    mysql> select * from emp limit 1,5;
    +-----+--------+-----+--------+--------+----------+---------------------+---------------------+
    | eid | ename  | sex | salary | deptid | leaderid | birdate             | income              |
    +-----+--------+-----+--------+--------+----------+---------------------+---------------------+
    |   2 | 李小龙 | 男  |  20000 |   1001 |        1 | 1983-06-07 00:00:00 | 2012-05-05 00:00:00 |
    |   3 | 成龙   | 男  |  23000 |   1002 |        2 | 1973-06-07 00:00:00 | 2013-05-05 00:00:00 |
    |   4 | 杨明   | 男  |  22000 |   1003 |        2 | 1993-06-09 00:00:00 | 2013-05-06 00:00:00 |
    |   5 | 黎明   | 男  |  28000 |   1004 |        3 | 1992-08-09 00:00:00 | 2013-07-06 00:00:00 |
    |   6 | 范冰冰 | 女  |  12000 |   1005 |        4 | 1994-08-09 00:00:00 | 2014-07-06 00:00:00 |
    +-----+--------+-----+--------+--------+----------+---------------------+---------------------+
    复制代码

    总结:  limit后面可以接一个数字,表示拿几条数据,默认从第一条开始拿; limit后面可以接两个数字,第一个数字代表 从该数字起, 第二个数字代表 拿多少条。

  • 相关阅读:
    对类对象使用new时地址分配的情况
    c++堆与栈的简单认识
    多态公有继承
    Cookie & Session & JSP入门
    Response & ServletContext
    Java网络编程篇文章阅读顺序
    URL编程
    UDP网络编程
    TCP网络编程
    InetAddress类的使用
  • 原文地址:https://www.cnblogs.com/insane-Mr-Li/p/11634221.html
Copyright © 2020-2023  润新知