01 6資料庫連線

2021-08-19 23:51:21 字數 834 閱讀 6466

子查詢(sub query)也稱為查詢的巢狀

使用子查詢:可以簡化思路,化繁為簡,分而治之

可分為:1)非關聯子查詢(常見) 2)關聯子查詢 子查詢的結果參與表連線

eg,求出誰的工資最低

思路:先求出最低工資,才求出最低工資的人是誰

1、select min(salary) from t_emp --750

2、select id,name,salaryfrom t_emp where salary=750 --tom

合併 select id,name ,salary from t_emp where salary=(select min(salary) from t_emp))

id first_name          salary

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

20 tom                          750

1)主查詢

最外層提供最後結果

select id, first_name, salary

from s_emp

where salary = (...);

2)子查詢   裡層  提供部分功能

select min(salary) from s_emp

子查詢的順序:先執行子查詢,返回結果後,在執行主查詢

子查詢的結果:一般都要有結果

1)一條記錄、單值   salary = 750    min(salary) -> 750

2)多條記錄、多值   in(31, 32, 33)   not in

3)無記錄、無值     幾乎不用

資料庫連線

第一,設定允許遠端連線,允許sql server驗證 第二,建立登陸帳戶並授權 第三,註冊sql server資料庫 c windows microsoft.net framework v2.0.50727 下執行 aspnet regsql 指令 data server sqlexpress in...

資料庫連線

php host localhost host name db user root mysql username db password root mysql password db name table database name connect to server and select data...

資料庫連線

1.c 連線連線access 程式 using system.data using system.data.oledb string strconnection provider microsoft.jet.oledb.4.0 strconnection data source c begaspne...