Many rows can have t1.name="foo".
MySQL will not update that row, if it detects that you already have the value you try to enter
But only the joined t1 rows that are linked to the condition t2.name="bar" will show up in the following query
select t1.id from t1
inner join t2 on t1.id=t2.id
where t2.name="bar";
Of course it will not detect , if t1.name has already the value "foo" and so it would show t1.ids that are not affected.
If you need the actual row, without the not affted rows, you must write a stired procedure where you
- SELECT the ids where already the t1.name is 'foo'
- UPDATE your table
- Do the above Query and remove all ids that are in 1.
As an Example
CREATE TABLE t1 (id int auto_increment primary key,name varchar(4));
INSERT INTO t1(name) VALUES('foo'),('foo1'), ('foo'), ('test'), ('test'), ('test'), ('test'), ('test'), ('test'), ('test');
CREATE TABLE t2 (id int auto_increment primary key,name varchar(4));
INSERT INTO t2(name) VALUES('bar'),('foo1'), ('bar'), ('bar'), ('bar'), ('test'), ('bar'), ('test'), ('test'), ('test');
SELECT * FROm t1;
id | name
-: | :---
1 | foo
2 | foo1
3 | foo
4 | test
5 | test
6 | test
7 | test
8 | test
9 | test
10 | test
SELECT * FROM t2;
id | name
-: | :---
1 | bar
2 | foo1
3 | bar
4 | bar
5 | bar
6 | test
7 | bar
8 | test
9 | test
10 | test
CREATE TEMPORARY table t1_temp SELECT id FROM t1 WHERE name = 'foo';
update t1
inner join t2 on t1.id=t2.id
set t1.name="foo" where t2.name="bar";
SELECT * FROM t1;
id | name
-: | :---
1 | foo
2 | foo1
3 | foo
4 | foo
5 | foo
6 | test
7 | foo
8 | test
9 | test
10 | test
select t1.id from t1
inner join t2 on t1.id=t2.id
where t2.name="bar" AND t1.id NOT IN (SELECT id FROM t1_temp);
| id |
| -: |
| 4 |
| 5 |
| 7 |
db<>fiddle here