Copy Column Value from One table into Another Matching IDs - SQLite

荒凉一梦 提交于 2020-01-15 11:46:07

问题


I want to do exactly what it was described in this question: (Copy Column Value from One table into Another Matching IDs), but in SQLite instead of MySQL.

The solution provided:

update t1, t2 set t1.value = t2.p_value where t1.id=t2.parent_id

returns an error near ","... If I say

update t1 set t1.value = t2.p_value where t1.id=t2.parent_id

returns an error near "."

I was not expecting the syntax of MySQL being so different from SQLite.


回答1:


You could try

UPDATE t1 
SET  t1.value = ( 
     SELECT t2.p_value 
     FROM t2 
     WHERE t1.id = t2.parent_id) 

or using you code try

UPDATE t1 
SET value = ( 
  SELECT value 
  FROM t2 
  WHERE t1.id = t2.id)


来源:https://stackoverflow.com/questions/57414183/copy-column-value-from-one-table-into-another-matching-ids-sqlite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!