查询:在sql语句中表名和字段名加上、 加快sql语句的运行速度
语法:
语法:select `字段 ,`字段` from `表名`
select `name` ,`title` from `liuyanban` 查询liuyanban表中name和title字段
select * from `liuyanban` 查询liuyanban表中所有字段 *代表所有
where:
语法:select * from `表名` where `字段`=1
select * from `liuyanban` where `id`=1 查询liuyanban表中id=1的数据
select * from `liuyanban` where `id`<>1 查询liuyanban表中id不等于1的数据
select * from `liuyanban` where `id`!=1 查询liuyanban表中id不等于1的数据
select * from `liuyanban` where `id`<1 查询liuyanban表中id小于1的数据
select * from `liuyanban` where `id`>2 查询liuyanban表中id大于2的数据
select * from `liuyanban` where `id` in(1,2,3) 查询liuyanban表中id的值在in的()里面的数据
select * from `liuyanban` where `id` not in(1,2,3) 查询liuyanban表中id的值不在in的()里面的数据
select * from `liuyanban` where `id` between 2 and 4 查询liuyanban表中id的值2-4之间
select * from `admin` where `name`='admin' and `pwd`='admin123' 查询admin表中name=admin 并且 pwd=admin123的数据
select * from `admin` where `name`='admin' or `pwd`='admin123' or或者
select * from `liuyanban` order by `time` desc 以降序的方式查询liuyanban表中 asc升序
select * from `liuyanban` where `id` in(1,2,3) order by `time` desc
如果有where条件order by必须放在where条件的后面
select * from `liuyanban` limit 0,3 现在查询的条数 语法:limit 起始位置,查询的条数 第一条的位置是0
select * from `liuyanban` where `id` in(1,2,3) order by `time` desc limit 0,3
where order by limit 顺序不能乱
select count(*) from `liuyanban` 查询表中总的数据条数
select count(*) as allnum from `liuyanban` as取别名
select max(id) from `liuyanban` 查询表中最大的id值
select min(id) from `liuyanban` 查询表中最小的id值
select avg(id) from `liuyanban` 查询表中id的平均值
select sum(id) from `liuyanban` 查询表中id的和
添加:
insert into 表名(字段,字段,字段) value (值1,值2,值3)
insert into `admin` (`name`,`pwd`) value('root' ,'root123' )
修改:
update 表名 set 字段=值1,字段=值2,字段=值3 where 条件
update `admin` set `name `='user',`pwd`='user123' where `id`=2
删除:
delete from表名where 条件
delete from `liuyanban` where `id`=4