zoukankan      html  css  js  c++  java
  • 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后面可以接两个数字,第一个数字代表 从该数字起, 第二个数字代表 拿多少条。

  • 相关阅读:
    sql中的并、交、差
    白水的sql需求:每个病人的对应最小诊断类别|partition|
    |转|oracle行转列点评oracle11g sql新功能pivot/unpivot
    oracle wm_concat(column)函数的使用不同公司支付同一客商(行转列)|转|
    记录那些删除的伴我成长的触发器
    PL/SQL Developer使用技巧|F=Forwarding|
    手工创建数据库 ocp课程 wait for
    Oracle数据库监听配置|转|
    最新解决的sql:病人相邻两次看病小于3天
    tns的一些常见错误分析实例 |转|
  • 原文地址:https://www.cnblogs.com/insane-Mr-Li/p/11634221.html
Copyright © 2011-2022 走看看