UPDATING multiple rows with SELECT

I have a table and two rows with id = 1 and id = 2, and their parameter x is 1. I also have table B and two rows with the same identifiers 1 and 2. I am trying to update all the data (column) on table B , which has the same identifier with table A, whose parameter x is 1.

Table

id | x | 1 | 1 | 2 | 1 | 

Table B

 id | Y | 1 | yes| 2 | yes| 

My request

  UPDATE B SET y='No' WHERE B.id=(SELECT A.id FROM A WHERE Ax=1); 

The problem is that select returns mutliple data, and I can only update the first data. I tried to use JOIN, but sqlite gives a syntax error near INNER, I could not find the problem.

  UPDATE B SET By='No' INNER JOIN A ON B.id=A.id WHERE Ax=1; 
+4
source share
1 answer

Use this:

 UPDATE ... WHERE B.id IN (SELECT A.id ...); 
+7
source

Source: https://habr.com/ru/post/1443242/


All Articles