-- 查出沒有明細資料對應的主檔資料 SELECT T1.IDEN from TBL_R0712_Iden as t1 LEFT join TBL_R0712_IdenMonth as t2 on t1.IDEN=t2.IDEN where T2.IDEN IS NULL -- 查出沒有主檔資料的明細資料 SELECT T1.IDEN from TBL_R0712_IdenMonth as t1 LEFT join TBL_R0712_Iden as t2 on t1.IDEN=t2.IDEN where T2.IDEN IS NULL -- 查出重複的資料 SELECT uname FROM Duplicate GROUP BY uname HAVING COUNT(*)>1