組合查詢很容易理解就是講多個(gè)查詢的結(jié)果放在一起顯示
使用UNION關(guān)鍵字進(jìn)行查詢的組合
創(chuàng)建組合查詢
select cust_name, cust_contact, cust_email
from customers
where cust_state in('IL','IN','MI')
UNION
select cust_name,cust_contact,cust_email
from customers
where cust_name = 'Fun4All';
將兩個(gè)查詢的結(jié)果組合在一起通過union關(guān)鍵字
union的使用規(guī)則
- union必須包含兩條或者兩條以上的查詢的句子
- union中每個(gè)查詢必須包含相同的列,表達(dá)式和聚集函數(shù),但順序可以不一樣