programmerJavaPL programmerJavaPL - 3 months ago 11
SQL Question

SQL (SQLite) Search from table1 and update in table2

As in title I need search a value in table1 and update table2.

table1

|id | nameEN | namePL|
----------------------
|1 | Cat | Kot |
|2 | Cow | Krowa |
|3 | Dog | Pies |


table2

|id | nameEN | namePL|
----------------------
|1 | Cow | |
|2 | Dog | |


I need search a translation in table1 for words in table2.

After I will show table2 in TableView in Java.

How to resolve a problem?

Answer

In SQLite, Update with JOIN won't work, so you can use the below query to UPDATE the values in to table2

UPDATE table2
SET namePL = (
        SELECT namePL
        FROM table1
        WHERE nameEN = table2.nameEN
        )
WHERE namePL = ''