We can easily copy the values within a table. But can we copy the values from one table to another table?. Yes, you can done it in mysql. The mysql query is:
Insert into table2 (column_name1, column_name2)
select column_name1, column_name2 from table1
Consider the example:
Table1 is name of this table.
Insert into table2 (column_name1, column_name2)
select column_name1, column_name2 from table1
Consider the example:
Table1 is name of this table.
Table2 is name of this table.
Copy values from one table1 to table2 in mysql:
Now you have to add values from 'Table1' to 'Table2'. The following mysql query is used to do it.Insert into Table2 (No,Game_name,Image)
select No,Game_Name, Image from Table1
The output of 'Table2' is:
Now you'll get values in 'Table2' which is same as 'Table1'.
If you want to some coulmn values, then you will add only required column name only in mysql query. Suppose you need only particular values. Then you use 'where' clause to get your answer. The mysql query as follow as:
Copy values from one table to another except some values in mysql:
If you want to some coulmn values, then you will add only required column name only in mysql query. Suppose you need only particular values. Then you use 'where' clause to get your answer. The mysql query as follow as:
Insert into Table2 (No,Game_name,Image)
select No,Game_Name, Image from Table1
where Game_Name='sample1' and Game_Name='sample2'
Then the output look like this:
Now you will get values only named in sample1 and sample2.
Related Post:
can any one give me full code..????
ReplyDeleteYou need to just add this query into your php code:
Deletemysql_connect('localhost','root','') or die('Cannot connect mysql server');
mysql_select_db('new') or die('cannot connect database');
$query=mysql_query("Insert into Table2 (No,Game_name,Image)
select No,Game_Name, Image from Table1") or die(mysql_error());
Right,... Thanks
ReplyDeletethanks
ReplyDelete