开发者

In SQLite, how can I update a column in TABLE A with the values from a column in TABLE B?

开发者 https://www.devze.com 2023-03-02 20:47 出处:网络
Need help with this as I m having no luck. Table A idgroupid 1100 2101 3102 Table B groupidnewid 100100 101开发者_运维知识库100

Need help with this as I m having no luck.

Table A

id   groupid   
 1     100   
 2     101   
 3     102  

Table B

groupid   newid  
 100        100  
 101开发者_运维知识库        100   
 102        100 

Update Table A so that Table A becomes

id   groupid   
 1     100   
 2     100   
 3     100  

which uses TableB to get the newid.

Thanks in advance


sqlite doesn't support joins in updates, but you could use a subquery. try something like this:

update a
set groupid = coalesce(
 (select newid from b where groupid = a.groupid limit 1),
 groupid
);
0

精彩评论

暂无评论...
验证码 换一张
取 消