I have the following table:
ID, initials, surname, company, active
1, p, abc, com1, 0
2, p, abc, com1, 0
3, c, acb, com1, 0
4, c, def, com1, 0
5, c, def, com1, 0
Now I want to update the duplicate combination of "initials, surname, company" to the status 1, resulting in the following:
ID, initials, surname, company, active
1, p, abc, com1, 0
2, p, abc, com1, 1
3, c, acb, com1, 0
4, c, def, com1, 0
5, c, def, com1, 1
The select is working:
SELECT DISTINCT initials, surname, company
FROM table
I tried this, but isn't working:
UPDATE table
SET active = 1
WHERE EXISTS( SELECT DISTINCT initials, surname, company)
That is, for each row, update it if there exists another row with a lower id, with the same initials, surname, and company.
Here’s an sqlfiddle for it.