一:增加数据的三种方式
1 insert into 表名 values(值1,值2,—)
2 insert into 表名(字段1,字段2,字段三—)values(
值1,值2,值3—)
3 insert into 表名 (字段1,字段2—)values(值1,值2—),
(值1,值2—)
二:删除数据
1 delete from 表名 where 条件(不加条件代表全删)
三:更新数据
1 update 表名 set 字段1=值1,字段2=值2,where 条件
四:查询数据
1 select *from 表名查询全部
2 select 字段 from 表名
3 select 字段 from 表名 where 条件
where后面跟的条件
1 关系 <,>,<=,>=,!=,
2 逻辑 or,and
3 区间 id between 4 and 6
五:排序
1 select 字段 from 表名 order by 字段 desc(–降序–)/asc(–升序–)
2 select *from 表名 order by 字段1 desc,字段2 asc;
3 多字段排序
select *from order by 字段1 desc,字段2 asc—;
六:多表联查
1内连接:关键字inner join on,取两个表交集部分
select *from A a inner join B b on a.a_id=b.b_id;
2 左外连接 left join on 左表全取,右表取符合条件的记录
select from A a left join B b on a.a_id=b.b_id;
3 右外连接 right join on ,右表全取,左表取符合条件的
selectfrom A a right join B b on a.a_id=b.b_id;
4 全连接
(select id,name from A)union (select num,age from B)