How to find all the foreign key records that do not have a primary key using a subquery (a query inside a query). Subquerys can produce the same result set as a Join as well the opposite of a join result set 如何利用子查詢找出沒有主關鍵值的資料。子查詢可產生與join相反的結果。
src: [Video 42 - SQL SubQuery](https://thefrugalcomputerguy.com/grouppg.php?ser=15&grp=15)(https://youtu.be/X87P7ADNF_4)
join 以外的資料
select distinct "phn"."employee-id" from "tbl_emp-phn-original" as "phn" where "phn"."employee-id" not in ( select "emp".employee-id" from "tbl_employees-original" as "emp" )
第2支
delete from "tbl_emp-phn-orignial" where "employee-id" in ( select distinct "emp-phn"."employee-id" from "tbl_emp-phn-original" as "emp-phn" where "emp-phn"."employee-id" not in (select "emp"."employee-id" from "tbl_employees" as "emp" ) )
文章標籤
全站熱搜
留言列表