如何找到基于单列的重复行。我在oracle中有一个表,该表具有下面给出的数据,并且有重复项。我正在尝试选择并查看具有重复员工ID的所有行,如下所述
EMP表:
EmpId Fname Lname Mname Jobcode Status exp_date 1 Mike Jordan A IT W 12/2014 1 Mike Jordan A IT A 12/2014 2 Angela ruth C sales P 12/2015 2 Angela ruth C IT W 12/2015 3 Kelly Mike B sales W 12/2015
从上面的表格中,我想选择所有重复如下所示的行的行
EmpId Fname Lname Mname Jobcode Status exp_date 1 Mike Jordan A IT W 12/2014 1 Mike Jordan A IT A 12/2014 2 Angela ruth C sales P 12/2015 2 Angela ruth C IT W 12/2015
我怎样才能做到这一点?谢谢你!
SELECT a.* FROM TableName a INNER JOIN ( SELECT EmpID FROM TableName GROUP BY EmpID HAVING COUNT(*) > 1 ) b ON a.EmpID = b.EmpID
尽管我更喜欢上面的 方法, 但是 另一种方法是使用IN
IN
SELECT a.* FROM TableName a WHERE EmpId IN ( SELECT EmpId FROM TableName GROUP BY EmpId HAVING COUNT(*) > 1 )