1陷谱、使用查詢where、limit
where:查詢條件
limit:限制查詢結(jié)果顯示的數(shù)量
題目:查詢students表中age<25的數(shù)據(jù)瑟蜈,并顯示這些數(shù)據(jù)的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"的所有數(shù)據(jù)
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 區(qū)分大小寫(只會查詢出大寫或者小寫的數(shù)據(jù)):
題目:查詢出students表name=“l(fā)ili”的所有數(shù)據(jù)
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的數(shù)據(jù)(包括大小寫在內(nèi))
題目:查詢students表name="lili"的所有數(shù)據(jù)
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條數(shù)據(jù)位迂,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;