UPDATE SET值来自另一个表的WHERE数据

时间:2013-12-04 07:01:33

标签: sql sqlite set

UPDATE kid_progress_Backup
SET    level = 9 (column in kid_progress_Backup)
FROM   users1
WHERE birthyear_string = 01/01/2001 (column in users1)

所以基本上我在这个论坛上看到的所有问题都是关于将一​​列value =设置为另一列中另一列的值。但我的不是。我想要

kid_progress_Backup.level = 9 
IF
users1.birthyear_string = 01/01/2001
AND
kid_progress_Backup.level = 8 
IF
users1.birthyear_string = 01/01/2002
WHERE
id>270

1 个答案:

答案 0 :(得分:0)

您应该在两个表之间维护一个外键。在你的情况下

kid_progress_Backup,users1 tables

假设uid是外键,那么您可以将查询写为

UPDATE kid_progress_Backup
SET    level = '9' where uid In(Select uid from  users1
WHERE birthyear_string = '01/01/2001')