1.联合查询
语法:
select 字段|常量|表达式|函数 [from 表] [where 条件] union [all]
select 字段|常量|表达式|函数 [from 表] [where 条件] union [all]
select 字段|常量|表达式|函数 [from 表] [where 条件] union [all]
...
select 字段|常量|表达式|函数 [from 表] [where 条件] ;
特点:
1)、多条查询语句的查询列数必须是一致的。
2)、多条查询语句的查询的列的类型几乎相同。
3)、union代表去重,union all代表不去重。
2.修改
修改单表语法:
update 表名 set 字段1=新值,字段2=新值 [where 条件];
修改多表语法:
update 表1 别名
inner|left|right join 表2 别名
on 连接条件
set 列=值,...
where 筛选条件;
3.删除
1)delete语句
单表的删除:
delete from 表名 [where 筛选条件];
多表的删除:
delete 别名1,别名2
from 表1 别名1,表2 别名2
where 连接条件
and 筛选条件;
2)truncate语句
truncate table 表名;
3)区别:
<1>truncate不能加where条件,而delete可以。
<2>truncate由于没有筛选条件,效率比delete高。
<3>truncate删除自增长的列的表后,当重新插入数据时,数据从1开始,而delete从上一次的断点处开始。
<4>truncate删除不能回滚,而delete删除可以回滚。