Search code examples
mysqljoindatatableinner-join

How we joined two database tables each other. In PHP simple way


How I join two table? Yes I reads all various posts on stackoverflow but it is not matching that. Even when I try to create it doesn't happened.

WHAT IS MY PROBLEM

I want insert data in table 2 from table 1

WHAT IS MY PROJECT

TABLE 1

customerID   Name       Password      Address
 1001           jinesh     secret        INDIA
 2003           mahesh     secret        USA

INSERT INTO TABLE 2

  ID        UserName  UseePass
   1        jinesh    secret  
   2        mahesh    secrey 

How I make like this.

I AM CODING

 // start
 $sql = $con->query("INSERT INTO table2 (UserName,UserPass) VALUE($name,$pass) FROM table1 INNER JOIN table1 password = $pass");
 // End 

Solution

  • Have you tried something like this ?

    INSERT INTO table2 (UserName, UseePass) 
    SELECT Name, Password FROM table1
    

    I'm assuming the ID column in table2 is and auto_increment so I'm skipping it in the insert statement