0

so i have two tables like this

TableA :

|  id  | name  | src  |
-----------------------
|   1  | T100  | B001 |
|   2  | T100  | B002 |
|   3  | T100  | B003 |
|   4  | T101  | B004 |
|   5  | T101  | B005 |
-----------------------

TableB :

| id | name | flag |
--------------------
| 1  | B001 |   1  |
| 2  | B002 |   1  |
| 3  | B003 |   1  |
| 4  | B004 |   1  |
| 5  | B005 |   1  |
--------------------

i want to update flag in TableB to 0 which used as src on T100 in TableA

TableB that i want after update :

| id | name | flag |
--------------------
| 1  | B001 |   0  |
| 2  | B002 |   0  |
| 3  | B003 |   0  |
| 4  | B004 |   1  |
| 5  | B005 |   1  |
--------------------

here is my query

UPDATE TableB SET flag = 0
FROM TableB b INNER JOIN TableA a 
ON b.name = a.src
WHERE a.name = T100

but the result is, it updates all the flag to 0, not just the T100 sources

TableB query result :

| id | name | flag |
--------------------
| 1  | B001 |   0  |
| 2  | B002 |   0  |
| 3  | B003 |   0  |
| 4  | B004 |   0  |
| 5  | B005 |   0  |
--------------------

is something in my query that i do wrong or is there another way to solve this? Thankyou

a_horse_with_no_name
  • 497,550
  • 91
  • 775
  • 843
Sakura
  • 1
  • 1

0 Answers0