mysql limit where_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;

b1cf78c56251

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值