Search code examples
phpmysqlmany-to-manyinner-join

many to many in MySql


I have two tables,

enter image description here

want to copy/update Code from Table 1 in Table 2 against Email address. Each email address have its own code. Email is the only column available for Join.

With my Query its update first Code to all other emails in Table 2. See my query

UPDATE table1 fb INNER JOIN table2 nb ON fb.email = nb.email SET fb.code = nb.code

did so many other tests, but it doesn't work. Any Suggestion ?


Solution

  • I noticed table 1 has a column "Code" but table 2 has a column "code" (uppercase/lowercase)

    If it becomes a hassle, just run two queries.

    First grab the code for the first table

    "SELECT code FROM table1 WHERE email='emailaddress'"
    

    then update the code on the second table

    "UPDATE table2 SET code='retrievedcode' WHERE email='emailaddress'"