php - Assigning the value to a column from a sql query -


i have 2 tables , need selelct of columns table1 , copy columns in table2. have tried many options nothing working me. beginner in php , mysql field . these things have tried first.

 `$sql = " update table1 join table2 on  table1.primary_key =  table2.primary_key  set table1.column1= table2.column1 , table1.column2=  table2.column2  table1.primary_key = 1  "; 

and

`$sql= "update table1 set table1.column1 =  table2.column1  table1 inner join               table2 on table1.primary_key =   table2.primary_key table2.primary_key= 1 "; 

and because of reason bothof them not working, tried method:

              $sql= "select column1,column2from table2 primary_key=1";               $result = mysql_query($sql);               $row = mysql_fetch_array($result);`               $updatequery ="update  table1 set column1=$row[column1] ,column2=$row[column2] primary_key= 1";                 mysql_query($updatequery); 

this throwing error . can 1 tel me how assign column value sql query or ny other methods satisfy need .

one option use join inside sql query during update:

update table1 t1 join (     select * table2     table2.primary_key = 1 ) t2 on t1.primary_key = t2.primary_key set t1.column1 = t2.column1 

i leave insert php code since many details not present in original problem.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -