Flying Flying - 5 months ago 9
MySQL Question

Transfering columns between tables that have a relationship

I have two tables:

table_Names

id, name

11, Harry

12, Wayne

13, Raheem

14, Manuel

15, Thomas

table_relationship

A_id, B_id

11, 14

12, 15

I need all the names for the ids that has the A-B relationships to update.

So, I want table_Names to look like this after the SQL update;

11, Manuel

12, Thomas

13, Raheem

14, Manuel

15, Thomas

How should the mySQL statement look like?

Edit:
I tried this:

UPDATE table_Names

INNER JOIN table_relationship

ON table_Names.id = A.id

SET table_Names=table_Names

WHERE table_relationship.Aid=table_names.id

Answer
UPDATE table_Names AS t1
INNER JOIN table_relationship AS t2
    ON t1.id = t2.A_id
INNER JOIN table_Names t3
    ON t2.B_id = t3.id
SET t1.name = t3.name