mysql select ,where,limit查询

1、使用查询where、limit

where:查询条件

limit:限制查询结果显示的数量

题目:查询students表中age<25的数据,并显示这些数据的id 、name、age

mysql>select id,name,age from students where  age <25  limit  2;

+----+------+-----+

| id | name | age |

+----+------+-----+

|  1 | lili |  12 |

|  3 | jujo |  21 |

+----+------+-----+

2 rows in set (0.00 sec)

2、使用where

题目:查找students表中name="lili"的所有数据

mysql> select * from students where name ="lili";

+----+------+-----+-----+-------------+

| id | name | sex | age | tel        |

+----+------+-----+-----+-------------+

|  1 | lili | f  |  12 | 13501665963 |

|  7 | lili | f  |  11 | 15110021003 |

+----+------+-----+-----+-------------+

2 rows in set (0.00 sec)

3、使用BINARY 区分大小写(只会查询出大写或者小写的数据):

题目:查询出students表name=“lili”的所有数据

mysql> select * from students where  BINARY  name ="lili";

+----+------+-----+-----+-------------+

| id | name | sex | age | tel        |

+----+------+-----+-----+-------------+

|  1 | lili | f  |  12 | 13501665963 |

|  7 | lili | f  |  11 | 15110021003 |

+----+------+-----+-----+-------------+

2 rows in set (0.00 sec)

没有BINARY 查询出所有name为lili的数据(包括大小写在内)

题目:查询students表name="lili"的所有数据

mysql> select * from studentswherename ="lili";

+----+------+-----+-----+-------------+

| id | name | sex | age | tel        |

+----+------+-----+-----+-------------+

|  1 | lili | f  |  12 | 13501665963 |

|  7 | lili | f  |  11 | 15110021003 |

|  8 | LiLi | f  |  10 | 18710051006 |

+----+------+-----+-----+-------------+

3 rows in set (0.00 sec)

mysql> select*from students whereBINARYname ="LiLi";

+----+------+-----+-----+-------------+

| id | name | sex | age | tel        |

+----+------+-----+-----+-------------+

|  8 | LiLi | f  |  10 | 18710051006 |

+----+------+-----+-----+-------------+

1 row in set (0.00 sec)

4、limit和offset

①limit后面跟的是2条数据,offset后面是从第1条开始读取

mysql> select*from master where id >10  limit  2 offset 1;

②limit后面是从第2条开始读,读取1条信息

mysql> select*from master where id >10limit 2,1;

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 一. Java基础部分.................................................
    wy_sure阅读 3,882评论 0 11
  • 1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语...
    子非鱼_t_阅读 31,874评论 18 399
  • 什么是数据库? 数据库是存储数据的集合的单独的应用程序。每个数据库具有一个或多个不同的API,用于创建,访问,管理...
    chen_000阅读 4,076评论 0 19
  • 一觉醒来, 天已大亮 赖在床上, 真的不想起床, 睡不着, 睁着眼躺着, 亦是幸福的状态。 躺在床上的我 昏昏沉沉...
    枯藤残鸦阅读 135评论 1 2
  • 亲爱的朋友们大家好!我是网络骄阳,今天又给大家带来一款美食《香蕉蛋糕》,这是一款非常简单容易做的纸杯蛋糕,相信家人...
    feaf5a1303da阅读 919评论 7 23