子查詢定義:
- 單上子查詢舉例:
顯示與 員工 關平 同一部門的員工, 但不包括關平
select * from staff where staff.stdepno = (select staff.stdepno from staff where stname='關平') and staff.stname<> '關平' ;
- 多行子查詢舉例:
查詢與 部門編號10的工作相同的員工的信息, 但是不包括 部門10自己的。
select * from staff where stjob in (select distinct(stjob) from staff where stdepno=10) and stdepno<>10;