close
--Table Alias(別名)
select e.EMPLOYEE_ID,e.last_name,d.location_id,d.DEPARTMENT_ID--已經取了別名就不可以再寫全名了departments.DEPARTMENT_ID←(X)
from employees e join DEPARTMENTS d --employees別名e DEPARTMENTS別名d
on e.DEPARTMENT_ID = d.DEPARTMENT_ID;
輸出結果跟沒有別名一樣
EMPLOYEE_ID | last_name | location_id | DEPARTMENT_ID |
100 | King | 1700 | 90 |
101 | Kochhar | 1700 | 90 |
102 | De Haan | 1700 | 90 |
103 | Hunold | 1400 | 60 |
104 | Ernst | 1400 | 60 |
107 | Lorentz | 1400 | 60 |
124 | Mourgos | 1500 | 50 |
141 | Rajs | 1500 | 50 |
142 | Davies | 1500 | 50 |
143 | Matos | 1500 | 50 |
144 | Vargas | 1500 | 50 |
149 | Zlotkey | 2500 | 80 |
174 | Abel | 2500 | 80 |
176 | Taylor | 2500 | 80 |
200 | Whalen | 1700 | 10 |
201 | Hartstein | 1800 | 20 |
202 | Fay | 1800 | 20 |
205 | Higgins | 1700 | 110 |
206 | Gietz | 1700 | 11 |
--額外條件
select e.EMPLOYEE_ID,e.last_name,d.location_id,d.DEPARTMENT_ID
from employees e join DEPARTMENTS d
on e.DEPARTMENT_ID = d.DEPARTMENT_ID--篩選條件:欄目相同
where location_id>1500--增加設定篩選條件,where不能有兩個,只有一個資料表有的欄目可以不用加別名(欄目名)(也可以加)
and d.DEPARTMENT_ID<=90--可以再用"and"再增加條件
EMPLOYEE_ID | last_name | location_id | DEPARTMENT_ID |
100 | King | 1700 | 90 |
101 | Kochhar | 1700 | 90 |
102 | De Haan | 1700 | 90 |
149 | Zlotkey | 2500 | 80 |
174 | Abel | 2500 | 80 |
176 | Taylor | 2500 | 80 |
200 | Whalen | 1700 | 10 |
201 | Hartstein | 1800 | 20 |
202 | Fay | 1800 | 20 |
全站熱搜
留言列表