问题是这样的。
有3个表。
表1有字段id typeid cateid content
表2有字段typeid name
表3有字段cateid name
现在表1的typeid没有值,cateid有值,对应着表3的cateid
我现在想要更新表1中的typeid的值,要求是,表3里的name和表2里的name相等的typeid更新给表1的typeid。
比如:
表1里有一行是
id typeid cateid content
1 0 1 内容 表3中cateid=1的name是法国
表2中typeid=3的name是法国。
更新后,表1变成
id typeid cateid content
1 3 1 内容
有3个表。
表1有字段id typeid cateid content
表2有字段typeid name
表3有字段cateid name
现在表1的typeid没有值,cateid有值,对应着表3的cateid
我现在想要更新表1中的typeid的值,要求是,表3里的name和表2里的name相等的typeid更新给表1的typeid。
比如:
表1里有一行是
id typeid cateid content
1 0 1 内容 表3中cateid=1的name是法国
表2中typeid=3的name是法国。
更新后,表1变成
id typeid cateid content
1 3 1 内容
SQL 查询: UPDATE cdb_threads SET typeid = cdb_threadtypes.typeid FROM cdb_threads,
cdb_threadtypes,
cdb_threadcates WHERE cdb_threads.cateid = cdb_threadcates.cateid AND cdb_threadtypes.name = cdb_threadcates.name MySQL 返回: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from
cdb_threads,cdb_threadtypes,cdb_threadcates
where
cdb_threads.cateid=c' at line 5
where t2.name=t3.name and t1.cateid=t3.cateid
update 不能用from的
都认真看看手册吧