0

I have two tables, one contains author names and their contact addresses and the other includes author names and their IDs.

The author name in both tables has the same value and I want to get the ID from one table and update the other one where the names are the same.

I tried this query that I believe it works in T-SQL (the sub-query also works in MySQL) but it does not work in MySQL:

UPDATE authors
set ID = (select b.ID from authors a, authorsID b 
where trim(a.name)=trim(b.name));

Could you please advise me how to make this work? Thanks.

Ashkan
  • 159
  • 2
  • 10

2 Answers2

3
UPDATE authors a
inner join authorsID b on trim(a.name) = trim(b.name)
set a.ID = b.ID
juergen d
  • 201,996
  • 37
  • 293
  • 362
0

Query:

UPDATE authors
SET ID = (SELECT b.ID 
          FROM authorsID b
          WHERE trim(authors.name)=trim(b.name))
Justin
  • 9,634
  • 6
  • 35
  • 47