Reputation: 41
I have an employee table like:
Empid EmpName Remark
001 Bob
002 Harish
003 Tom
004 Dicky
001 Bob
003 Tom
I have to find the duplicate employee id and accordingly updating the remark field as duplicate !
Thanks.
Upvotes: 0
Views: 263
Reputation: 79808
update employee set remark = 'duplicate'
where empid in (
select empid
from employee
group by empid, empname
having count(*) > 1 )
Upvotes: 1
Reputation: 31631
Below will give you ID of duplicate records
`select empID, empName, count(empID) as cnt from fschema.myTable group by (empID) having cnt > 1 order by cnt`
Will get back to you how to set remark as 1 for duplicates shortly...
Upvotes: 0
Reputation: 80603
This question is very vague, because you do not mention what ORM library you are using or how you are accessing/manipulating your database. But basically want you want to do is execute a derived table query, then make a decision based on the results.
SELECT * FROM
(SELECT empId, count(empId) numIds from Employee group by empId) IdCount
WHERE numIds > 1;
Run this query via a PreparedStatement or whatever your ORM framework provides, then iterate over each result and update your remark field.
Upvotes: 0