Note that there are some explanatory texts on larger screens.

plurals
  1. POSyncing primary key between two tables stored in two different database
    primarykey
    data
    text
    <p>I have two MySQL database that contain two table, let's call them TABLE_A and TABLE_B. Both these tables have as fields <code>id</code> and <code>title</code>. Both databases are on the same server and the same user can access both.</p> <p>Now, TABLE_A is a subset of TABLE_B for what concern the <code>title</code> field. It means that every <code>title</code> in TABLE_A is present in TABLE_B, too. While <code>id</code> fields of the two table are in no way related.</p> <p>What I need is to sync <code>id</code> fields in TABLE_A with <code>id</code> fields in TABLE_B, according to the title, i.e. same <code>title</code>, same <code>id</code>. If it's not clear, I have to save TABLE_B <code>id</code> and override TABLE_A ones. And I DON'T have to add missing <code>title</code> from TABLE_B to TABLE_A.</p> <p>Someone suggested to use a temporal table where to copy all TABLE_B fields in common with TABLE_A and then rename it as TABLE_A. I cannot follow this way, as TABLE_A actually has also other fields that I need to maintain. So, I cannot entirely drop the old TABLE_A.</p> <p>Moreover, <code>id</code> is the primary key for both tables. It means that I cannot simply copy from TABLE_B to TABLE_A as the query will fail as soon as I try to change one <code>id</code> to another one that is already present in TABLE_A but linked to a different <code>title</code>.</p> <p>I know how to write a Perl or PHP script to do it, but I would like to know if a pure MySQL solution exists.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload