从一个表中选择所有数据并将其插入到另一个表中 [英] Select all data from a table and insert it to another table
本文介绍了从一个表中选择所有数据并将其插入到另一个表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从一个表中选择所有数据,然后将其插入到另一个表中.我有这段代码,但是没有用..phpMyadmin说的是"MySQL返回了一个空结果集(即零行).(查询花费了0.0010秒.")
I wanted to select all the data from one of my table and insert it to another table. I have this code but it wasn't working..This is what the phpMyadmin says "MySQL returned an empty result set (i.e. zero rows). (Query took 0.0010 seconds.)"
这是我的代码:
if(isset($_POST['select_table']))
{
$select_table = mysql_real_escape_string($_POST['select_table']);
$query_select = "INSERT INTO pdf_table
SELECT * FROM $select_table";
$select_query = mysql_query($query_select,$connectDatabase);
}
推荐答案
请确保两个表的列数相等. 使用以下方法通过select查询插入记录是一种好习惯:-
Please ensure that both the tables have equal number of columns. It is a good practice to use following way for inserting records with select query :-
INSERT INTO pdf_table (column_1, column_2) SELECT column_1, column_2 FROM $select_table
这篇关于从一个表中选择所有数据并将其插入到另一个表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文