Klimun Klimun - 5 months ago 23
SQL Question

SQLite inserting a select into a column

I would need help with a following case:

I have a table called Prevodnik with these columns:

Chaincode | Shopcode
2225 | XX2250
5552 | XX5548

Then there is a table called Prevodnik2 with following:

Chaincode | Shopcode
2225 |
5552 |

I need to join the shopcode records into the empty column Shopcode, but I can't make it work. So far I've tried something similar to this:

update prevodnik2 set shopcode =
(select prevodnik.shopcode from prevodnik LEFT JOIN prevodnik2 ON prevodnik2 = prevodnik.chaincode)

Would you happen to know what to do with this, please?

Thanks a lot!


The subquery leads to multiple rows, but only one is needed in the SET-clause. You can try the following. I don't know if SQLLite supports everything in this statement.

update prevodnik2 p2 set shopcode = (select p.shopcode from prevodnik p WHERE p2.chaincode = p.chaincode)