Update MySQL table column from another table entities


I have 2 tables and I need to update a column from table2 using a column in table1. table2.id2 is empty and I must fill it using table1.id. Also, you must know that I have 2 columns that can be matched with each other in these tables (table1.code and table2.code).This is my SQL :

UPDATE table2 SET table2.id2 = table1.id WHERE table2.code = table1.code;

Is this query right ? I'm getting this error, while I'm sure that table1.code exists.

[Err] 1054 - Unknown column 'table1.code' in 'where clause'


Assuming you can join both tables using code

  T2.ID2 = T1.ID
  T2.ID2 = '';

Recent Tips

  1. Shoot fireball once in unity C#
  2. Adding a table of contents to a Microsoft Word Document using vbs
  3. Change locale in android app (onto Hindi)
  4. How do I stop selenium automation if 20% or 1st 20 test cases test methods are failed?
  5. Sharepoint with silverlight app
  6. What's the best way to write robots.txt for github pages using multiple repos?
  7. Biopython: Cant use .count() for biopython
  8. How can I find out the token balance of an address?
  9. ref value is undefined in vue (modal, textarea, $refs)
  10. Azure - HDInsight Hbase Data Insertion Failed
  11. SignalR overwriting OnConnected(), OnDisconnected()
  12. DatePickerDialog displays with two borders
  13. "type 'double' is not a subtype of type 'int' in type cast" error in flutter. What should i do?
  14. hiding the autocomplete list when user click outside the textbox is not working as expected
  15. JSF IceFaces basic problem with redisplaying input value
  16. How to validate material ui TextField in reactjs?
  17. Go and MongoDB connection won't work with panic log "no reachable server"
  18. WordPress Posts Pagination Not Working
  19. F# sprintf won't print in interactive console
  20. Spring Integration get FTP files recursively with outbound-gateway
  21. Jade mixins not getting working from external file
  22. Can not access defined exports from the webpack bundle?
  23. Completely new to Node.js - API Programming
  24. Formatting Compare-Object Ouput
  25. Add dynamically added textbox value from User Control to main form
  26. Create a ByteBuf in Netty 4.0
  27. Is it possible to do computation before super() in the constructor?
  28. Q-learning Updating Frequency
  29. Wrong reload order when using Gulp and browserSync
  30. I use hugo build static page. But don't have content