---沒有去除重復的記錄 select distinct ContractLaborEmployeeUidKey,ContractLaborEndDate from ContractLaborList order by ContractLaborEndDate desc select * from ContractLaborList order by ContractLaborEmployeeUidKey ---沒有去除重復的記錄 select * from ContractLaborList where ContractLaborEmployeeUidKey in (select distinct ContractLaborEmployeeUidKey from ContractLaborList) order by ContractLaborEndDate desc --去除ContractLaborEmployeeUidKey重復的記錄 select * from ContractLaborList where ContractLaborEndDate in( SELECT MAX(ContractLaborEndDate) AS ContractLaborEndDate FROM ContractLaborList GROUP BY ContractLaborEmployeeUidKey) --重复行只查询一条 order by ContractLaborEndDate desc ---去除ContractLaborEmployeeUidKey重復的記錄 select * from ContractLaborList e WHERE e.ContractLaborEndDate = (SELECT max(x.ContractLaborEndDate) FROM ContractLaborList x WHERE x.ContractLaborEmployeeUidKey = e.ContractLaborEmployeeUidKey); SELECT * FROM View_ContractLaborList --取出ContractLaborEmployeeUidKey重復的值 SELECT * FROM ContractLaborList s2 WHERE 1 < (SELECT COUNT(*) FROM ContractLaborList s1 WHERE s1.ContractLaborEmployeeUidKey = s2.ContractLaborEmployeeUidKey)