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刪除可以回滾。