I have two tables, table_a and table_b:
table_a:
city
--------
tokoyo
london
table_b:
zipcode
-------
23675
11290
How to combine table_b to table_a, like this:
table_a:
city zipcode
-------- --------
tokoyo 23675
london 11290
Without a common column to join on, I don’t think you will be able to trust the results (as far as I know, MySQL does not guarantee that rows are returned in the order they are inserted).
But to be technical, I think you can achieve this in the following way: Don’t actually do this, see below
Forgive me if my syntax is off, it’s been a while.
This technique leverages what I think MySQL does when you add a non-null auto_increment column: it fills in the values for you, one unique value per row. Now you have a joining column, and can perform the update.
However, I’ll state this again to be very clear: If there really is no additional columns between the tables, you have no completely accurate way to join these two tables. You would need either a common join column, or at least each having an auto_increment column and the guarantee that all zipcodes and cities where entered in appropriate pairs in transactions.