Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
743 views
in Technique[技术] by (71.8m points)

sqlite - SQL - Update a table using a field of another table

I am trying to execute the following update query:

UPDATE Commodities 
INNER JOIN UniqueCountries 
     ON Commodities.wbCode = UniqueCountries.wbCode 
SET Idenb = UniqueCountries.wbName||yr

The query is clearly wrong, as it doesnt work. How can I fix it?


The query is supposed to update column IdenB with the concatenated value of wbName and yr (wbName||yr). However, wbName is on another table called UniqueCountries, which is why I tried to perform an Inner Join.

What am I doing wrong and how can I fix it? Thank you very much.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I can't see any indication in the docs that FROM or JOIN are supported in UPDATE statements.

Maybe you could try a correlated sub query if not.

UPDATE Commodities  
SET Idenb = (SELECT UniqueCountries.wbName||yr 
             FROM UniqueCountries 
             WHERE Commodities.wbCode = UniqueCountries.wbCode)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...