SQL语句,update

来源:百度知道 编辑:UC知道 时间:2024/05/17 10:22:59
假如有两个表
table1:date1,date2,date3
table2:dateA,dateB,dateC

现在我要更新table1,用table2中dateC等于table1中date3的那一行的dateB来代替date2请问怎么写?

eg:
table1:
11 22 33
12 23 34
13 24 35

table2:
111 222 333
112 113 34
1212 232 323

更新后table1变成
11 22 33
12 113 34
13 24 35

你还要在table1和table2表中加一个ID字段,并且table1每条数据的id要等于table2对应数据的id,
eg:
table1:id,date1,date2,date3
table2:id,dateA,dateB,dateC

table1:
1 11 22 33
2 12 23 34
3 13 24 35

table2:
1 111 222 333
2 112 113 34
3 1212 232 323

update table1,table2 set table1.date1=table2.dateA,table1.date2=table2.dateB,table1.date3=table2.dateC where table1.id=table2.id

update table1 set
date2=(select table2.dateB from table1,table2 where table1.date3=table2.dateC)
where table1.date3=(select table2.dateC from table1,table2 where table1.date3=table2.dateC)

感觉好复杂,哈哈