将表2的id和表1的id相同的记录,用表2的记录覆盖表1中的记录,
表1:
id name age
1 cc 10
2 jj 11
3 nn 14
表2:
id name age
2 ww 18
3 tt 15得到结果:
id name age
1 cc 10
2 ww 18
3 tt 15 语言表达能力不够,不知道描述清楚没有……
请各位高手指教!
表1:
id name age
1 cc 10
2 jj 11
3 nn 14
表2:
id name age
2 ww 18
3 tt 15得到结果:
id name age
1 cc 10
2 ww 18
3 tt 15 语言表达能力不够,不知道描述清楚没有……
请各位高手指教!
set tb1.name=tb2.name ,tb1.age=tb2.age
from tb2
where tb1.id=tb2.id
set t1.name=t2.name,t1.age=t2.age
from t1,t2
where t1.id=t2.id
不过我运行的时候显示 Near “.”:syntax error Unable to execute statement哪里错了呀?
我用的sqlite在sql browser查询语句编辑框里执行的,报了在“.”附近有错误
还请高手多指点 ,感激不尽啊!
update t1
set t1.name=t2.name,t1.age=t2.age
from t1,t2
where t1.id=t2.id
update t1
set t1.name=t2.name,t1.age=t2.age
from t2
where t1.id=t2.id
set t1.name=t2.name,t1.age=t2.age
from t2
where t1.id=t2.id
也还是说点附近有错误
刚刚查了一下说sqlite 的update 不支持别名 ,是不是这个原因呢
update t1
set name=(select name from t2 where id=t1.id),
age=(select age from t2 where id=t1.id);运行结果:
id name age
1
2 ww 18
3 tt 15
将t2中的数据复制到了t1中,但是t2中没有的id,就把t1中的数据清空了
set name=(select name from t2 where id=t1.id),
age=(select age from t2 where id=t1.id)
where t1.id=(select id from t2 where t1.id=t2.id)