select语句用于查询检索表中的数据,是mysql中最基本的语句之一,select语句的通用形式如下:
select 你要的信息 from 数据表 where 满足的条件
比如:
select * from mytable where id=1; /*查询mytable表中id为1的数据行*/
下面向大家介绍mysql select的各种使用情况。
1.结合where语句来设定查询检索条件
select * from score where score>95;
select last_name,first_name from president where last_name=’Tom’;
select last_name,first_name,birth,state from president where birth<’1950-1-1’ and (state=’VA’ or state=’BA’);
2.结合distinct关键字查询不重复记录
select distinct username from usertable; /*查询usertable表中所有不重复的username*/
3.结合order by和limit实现分页和排序
select * from mytable order by name; /*查询mytable表并按照name升序排序*/
select * from mytable order by name,id desc;/*按照name升序,id降序查询mytable表*/
select * from mytable order by name limit 1,3;/*按照name升序排序并只获取第二行到第四行数据*/
4.集合聚合函数(sum,count)实现统计查询
select count(*) from student where sex=’f’;/* http://www.manongjc.com/article/1412.html */
select count(*) from student where sex=’m;
select sex,count(*) f rom student group by sex; 继续阅读与本文标签相同的文章
上一篇 :
程序员必备!关系型数据库架构的超强总结
下一篇 :
php fileperms获取文件的权限
-
城市数字化后,新一代内生安全系统可全方位保护
2026-05-14栏目: 教程
-
谷歌也来“唱衰”5G,5G手机只会徒增功耗?为何这么说?
2026-05-14栏目: 教程
-
量子信息和量子技术白皮书合肥宣言在中科大发布
2026-05-14栏目: 教程
-
微信悄悄更新一新功能,来看看!
2026-05-14栏目: 教程
-
打破三大运营商垄断,第四大运营商终于来了!
2026-05-14栏目: 教程
