資料庫與Mysql 7

2021-10-07 09:34:20 字數 786 閱讀 9425

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

語法:

查詢語句1

union[all]

查詢語句2

union[all]

.......

應用場景:

要查詢的結果來自多個表,且多個表沒有直接的連線關係,但查詢的資訊一致(列數也要求一致)
特點

1.要求多條查詢

2.要求多條查詢語句的 其查詢的每一列的型別和順序最好一致

3.union 關鍵字預設去重,如果使用union all可以包含重複項

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

不使用union:

---------------------------

select *

from employees

where email like '%a%' or department_id > 90;

使用union:

----------------------------

select * from employees where email like ' %a%'

union

selcet * from employees whree department_id > 90;

MYSQL 7 資料庫優化 索引

索引型別 btree hash 普通索引 唯一索引 unique index 主鍵索引 組合索引 全文索引 fulltext index 建立索引 create table table name col name data type unique fulltext index key index n...

mysql7 資料庫的匯出匯入

匯出整個資料庫 注 這個是在沒有登陸mysql下,在控制台進行的操作 密碼可以不用輸,在回車之後輸入也可以 mysqldump u 使用者名稱 p 資料庫名 匯出的檔名 mysqldump uroot proot student student.sql匯出乙個表 一般不用 mysqldump u 使...

MYSQL 7 資料過濾

小於等於10,並且vend id為1001的資料 select prod id,prod name,prod price from products where prod price 10 and vend id 1001 產品 大於等於10,並且產品編號為1002或者為1003。返回的結果按 從高...