I am relatively new to this form and it would be of great help if anyone could clarify how to solve this specific use-case i am facing In My scenario.
I have 2 tables Table_A and Table_B
table_A has 2 fields id, status Table_A (id int, table_a_status int) where id is a primary key.
Table_B has 3 fields id, status Table_A (id int, table_a_id int, table_b_status int) where table_a_id is a foreign key and id is the primary key for Table_B.
Table_A
id table_a_status
1 1
2 1
Table_B
id table_a_id table_b_status
1 1 1
2 1 1
3 2 1
4 2 1
There are many ways to update multiple rows in multiple tables and currently i am using procedures to solve this, but its not quite efficient, I wanted to know an efficient way to update both the tables using a single query. I have tried using the queries:
UPDATE Table_A
INNER JOIN Table_B ON Table_B.table_a_id = Table_A.id
SET Table_A.table_a_status = 1, Table_B.table_b_status =1
WHERE Table_A.id IN (1,2);
UPDATE Table_A, Table_B
SET Table_A.table_a_status = 1, Table_B.table_b_status =1
WHERE Table_B.table_a_id = Table_A.id AND Table_A.id IN (1,2);
But both the queries are giving an error if i have a condition where i am updating for 2 id's (1,2) Operand code should contain 1 column, but it works when i update one id at a time eg)
UPDATE Table_A, Table_B
SET Table_A.table_a_status = 1, Table_B.table_b_status =1
WHERE Table_B.table_a_id = Table_A.id AND Table_A.id IN (1);
I know Operand code should contain 1 column error is invoked because the sub-query is returning more than one row in multiple table.
Is there any other way to update multiple rows in multiple tables at the same time