Reputation: 8741
I have used following the Table(emp) in my product.
id - name - Manager - dept- ismanager
101 - XXX - YYY - 1-0
102 - XX - YY - 2-0
103 - XXX - YYY - 1-0
104 - XX - YY - 2-0
105 - XXX - kkk - 2-0
106 - XX - zzz - 2-0
107 - XXX - YYY - 2-0
I want to update the isManager column value as 1, when the manager is YYY/YY. because those are repeatable in my Table. How can I solve it? I have tried to check condition in where like "update emp SET ismanager = '1' where Manager = 'YYY' and Manager = 'YY'; but in that case table will hit many times and I dont know about the what the value stored in the manger column. It will change runtime. Basically i want to know, if the 'manager' column value is repeated, I will update 'ismanager' column as '1'. Please Suggest me. How to do that?
This is, i can achieved as per CL(below) suggestion. Thanks CL.
Upvotes: 0
Views: 334
Reputation: 180250
UPDATE emp
SET ismanager = 1
WHERE Manager IN (SELECT Manager
FROM emp
GROUP BY Manager
HAVING COUNT(*) > 1)
Upvotes: 1