我有下表:
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
现在我想将“姓名首字母、姓氏、公司”的重复组合更新为状态1,结果如下:
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
选择正在工作:
SELECT DISTINCT initials, surname, company
FROM table
我试过这个,但不工作:
UPDATE table
SET active = 1
WHERE EXISTS( SELECT DISTINCT initials, surname, company)