By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,760 Members | 955 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,760 IT Pros & Developers. It's quick & easy.

How can i insert data in to a table from another database

P: 13
Hi,
Can any body tell that

suppose i have member table in database1

I want to insert data in to this table, getting data from another database table suppose database2 table

And is it possible ?
Thank you.
May 26 '07 #1
Share this Question
Share on Google+
3 Replies


Atli
Expert 5K+
P: 5,058
You can do somthing like this.

Expand|Select|Wrap|Line Numbers
  1.  
  2. INSERT INTO 
  3.   db1.myTbl(value)
  4. VALUES
  5.   ((
  6.     SELECT value
  7.     FROM db2.myTbl
  8.     LIMIT 1
  9.   ))
  10.  
May 26 '07 #2

P: 13
thank you. it will work in normal situation. my requirement is.
i created to objects for two databased located in different servers like this

$obj1= new mysqli("192.168.343.44", "user", "password", "db1");
$obj2=new mysqli("192.325.236.23","user","password","db2");

now we hvae two objects with two databases.

How can i insert into another table from ditterent database.

Help me.

Thank you.
May 28 '07 #3

blossam
P: 29
Hi,
Can any body tell that

suppose i have member table in database1

I want to insert data in to this table, getting data from another database table suppose database2 table

And is it possible ?
Thank you.

ya it is possible

u can run query like --->

if structure of the both tables are same then...
"insert into database1.member select * from database2.member"

if structure of both tables are not same then
"Insert into database1.member select columnname1,columnname2 from database2.member"

replace columnname1,columnname2 with required field name
May 31 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.