Jump to content


Photo

Copy Data problem


  • Please log in to reply
4 replies to this topic

#1 neugi

neugi
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 05 July 2006 - 08:13 AM

Hi,

i want to copy some data form one db to a other.

i tried this syntax but it don't worked:
INSERT INTO `testbd`.`ARTIKEL`
SELECT *
FROM `testdb2`.`ARTIKEL` , `testdb`.`ARTIKEL`
WHERE `testdb2`.`ARTIKEL`.`ARTNUM` >

MAX( `testdb`.`ARTIKEL`.`ARTNUM` )

what i want is, take all the article that are missing in the first databas and put it into the other database. based on the ARTNUM field.

best

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 05 July 2006 - 10:00 PM

What didn't work?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 07 July 2006 - 01:48 PM

try
INSERT INTO `testbd`.`ARTIKEL`
SELECT b.*
FROM `testdb2`.`ARTIKEL` b 
LEFT JOIN `testdb`.`ARTIKEL` a
	ON a.ARTNUM = b.ARTNUM
WHERE a.ARTNUM IS NULL

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#4 SQL_F1

SQL_F1
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 13 July 2006 - 08:11 AM

or

INSERT IGNORE INTO `testbd`.`ARTIKEL`
SELECT *
FROM `testdb2`.`ARTIKEL` 
to insert ALL the missing ones
although it seems you want to be inserting only the newer ones:

INSERT INTO `testbd`.`ARTIKEL`
SELECT *
FROM `testdb2`.`ARTIKEL` 
WHERE `testdb2`.`ARTIKEL`.`ARTNUM` >
(SELECT MAX( `testdb`.`ARTIKEL`.`ARTNUM` )
    FROM  `testdb`.`ARTIKEL`
)


#5 SQL_F1

SQL_F1
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 13 July 2006 - 08:12 AM

or

INSERT IGNORE INTO `testbd`.`ARTIKEL`
SELECT *
FROM `testdb2`.`ARTIKEL` 
to insert ALL the missing ones
although it seems you want to be inserting only the newer ones:

INSERT INTO `testbd`.`ARTIKEL`
SELECT *
FROM `testdb2`.`ARTIKEL` 
WHERE `testdb2`.`ARTIKEL`.`ARTNUM` >
(SELECT MAX( `testdb`.`ARTIKEL`.`ARTNUM` )
    FROM  `testdb`.`ARTIKEL`
)





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users