一张表relation ,有字段owner,con_id,里面已经有好多记录,owner与con_id是一个唯一键,求写一个UPDATE语句,
把owner='40'改成owner='35' (即要考虑避免与owner-con_id这个唯一键冲突)
owner con_id
40 12
40 13
35 12
最后形成
owner con_id
40 12
35 13
35 13
把owner='40'改成owner='35' (即要考虑避免与owner-con_id这个唯一键冲突)
owner con_id
40 12
40 13
35 12
最后形成
owner con_id
40 12
35 13
35 13
解决方案 »
- 困扰了我N天的大问题
- mysql select语句
- C#项目用mysql数据库服务器,乱码问题
- 有关MySQL5.1版本在linux 4下的安装问题,急!!!
- 各位高手帮帮忙,看看这个要求能不能用sql实现
- 急!!!如何让mysql-4.0.12不启用innodb
- 求助:关于linux下的MySQL数据恢复问题
- 有2个表 [color=#FF0000]lasttime_table[/color](登录时间表) [color=#FF00FF]regtime_table[/
- 数据库高手请进
- MYSQL 插入数据前,判断是否存在,存在就插入,怎么有错
- telnet 127.0.0.1 3306 连接失败
- mysql的多对多如何建立?
35 13
35 13
不是重复了?
update relation as r set r.owner ='35'
where r.owner='40' and not exists(select 1 from relation as t2 where t2.con_id =r.con_id and t2.owner='35')
但是这个语句执行不过去
Set owner ='35'
Where owner='40'
left join (select con_id from relation where owner = 35)b on b.con_id = a.con_id
set a.owner=35
where b.con_id is null;这个试试
update relation a
left join (select con_id from relation where owner = 35)b on b.con_id = a.con_id
set a.owner=35
where b.con_id is null and a.owner = 40;