0

I have 2 tables: Table1 (entry, x, y) Table2 (entry, x, y)

I want to update Table1.position1, sot it = Table2.Position1 where entries are the same(there are different entries in both tables, but some are the same)

So what I have tried to do:

update Table1 SET Table1.x = Table2.x where Table1.entry=Table2.entry;

But got error:

Unknown column 'Table2.entry' in 'where clause'

So then I tried to do another query:

update Table1 SET Table1.x=(select x from Table2) inner join Table2 on Table1.entry=Table2.entry;

But again got error

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'inner join Table2 on Table1.entry=Tab' at line 1

Any of the answers in google didn't gave me satisfactory result, so I hope someone can help. Thank you.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • This link here shows you how to update a value based on a SELECT from another table. https://stackoverflow.com/questions/2334712/how-do-i-update-from-a-select-in-sql-server – Nerdi.org Jul 15 '18 at 19:24

1 Answers1

0

The syntax in MySQL is:

update Table1 t1 join
       Table2 t2
       on t2.entry = t1.entry
    set t1.x = t2.x;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • How many times are you going to answer this question again and again without marking it a duplicate? – Shadow Jul 15 '18 at 20:01