16 聯合查詢

2021-10-18 14:50:13 字數 533 閱讀 3958

將多條查詢語句的結果合併成乙個結果

語法:

查詢語句1

union

查詢語句2

union..

.

應用場景:當要查詢的結果來自多個表,且之間沒有連線關係,就可以用聯合查詢

案例1:查詢部門編號》90或郵箱中包含a的員工資訊

select

*from employees where department_id >

90union

select

*from employees where email like

"%a%"

;

案例2:查詢中國使用者中男性的使用者資訊以及外國使用者男性的資訊

select

*from t_ca where *** =

"男"union

select

*from t_ua where *** =

"male"

注意事項:

Execl ADO SQL 聯合查詢

原題目 如何從兩張excel表中取數,生成第三張表?表一 a姓名 b身份證號 c金額1 張三642120197409020031 21002李四 552120197509020031 31003王五 693120197408020031 20004陳三 642202197409020031 1000...

SQL 聯合查詢

use xsgl go select from student select from cause select from exam 聯合查詢 join on 預設為inner,如果有right or left 那麼就指的是外聯,outer 可以不寫 1.最長見為內聯 table1 inner jo...

mysql聯合查詢

有乙個前提很重要 就是兩個表中的對應字段應該是建立聯合關係且該鍵應唯一 在查詢該聯合建的時候要指明 表.欄位 1.select from 表a,表a子表 where表a.filecode 表a子表.filecodeand表a.id in select 表a子表 id from 表a子表 where ...