'How can I UPDATE table using condition WHERE from another table in SQLite
I'm working with SQLite and I have two tables:
table1 table2
------------- --------------
id id
value condition
Column "id" contains the same data. And I need to:
UPDATE table1
SET table1.value = 'Some value'
WHERE table2.condition = 'Some condition"
I tried to use JOIN and FROM for linking tables with "id" column, but this isn`t working in SQLite. Please help with syntax.
Solution 1:[1]
Method 1 : Considering the two tables you have are "Table1" and "Table2", Updating Table1 can be done using a nested Select statement in which you will be selecting the data you need to update from Table2. For example:
UPDATE Table1
SET StudentID =
(
SELECT RegNo
FROM Table2 t
WHERE StudentID = RegNo
);
You can have a look on this link which solves a similar question : https://dba.stackexchange.com/questions/206317/update-values-in-one-table-from-data-in-another
Method 2 : You can use a table join. Refer the same link given above.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Shubham |
