0

I have searched many questions and ready many different articles about this but no one seems to help me out or may be I could not able to understand completely. I want to migrate data from one database to another database.
This is my query

$query = mysql_query("
    Insert into database2.table2 (id, data)
    select (id, name) from database1.table1
");
if($query == false){   
    die(mysql_error());   
}

When I execute this query it shows me this error message which is really annoying Operand should contain 1 column(s)

I searched about it but found nothing which could help me.

Note: This query is initally for my test case. Actual query will be made later.

Oswald
  • 31,254
  • 3
  • 43
  • 68
Husnain Ahmed
  • 135
  • 1
  • 1
  • 12

2 Answers2

1

Try this query (Removing parenthesis from select fields),

INSERT into database2.table2 (id, data) SELECT id, name from database1.table1

Note: Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO, or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

Zoe
  • 27,060
  • 21
  • 118
  • 148
Rikesh
  • 26,156
  • 14
  • 79
  • 87
0

remove the parenthesis from

select (id, name)

to

select id, name

final result:

$query = mysql_query("Insert into database2.table2 (id, data) select id, name from database1.table1");
STT LCU
  • 4,348
  • 4
  • 29
  • 47
  • Really appreciating your answer. Thanks but I have ticked one more question that will this query slow down my pc if the data is large? – Husnain Ahmed Apr 15 '13 at 10:42