View Full Version : Copy from Table 1 to Table 2
lansing
11-25-2008, 01:56 AM
I am trying to create a script that will copy certain data from Table 1 to Table 2. I have searched and found this code below, but I have duplicate entries in and the query stalls when it finds a duplicate entry. What I need help with is skipping any email address that is already in the newslist_subscription table.
INSERT INTO `newslist_subscription` ( email, listid )
SELECT `email` , '1'
FROM `customers` ;
PappaJohn
11-25-2008, 02:27 AM
If the email column is either the primary key or a unique key, you can use REPLACE (http://dev.mysql.com/doc/refman/5.1/en/replace.html) instead of INSERT
lansing
12-04-2008, 01:49 AM
If the email column is either the primary key or a unique key, you can use REPLACE (http://dev.mysql.com/doc/refman/5.1/en/replace.html) instead of INSERT
That worked perfectly. I have been using it, but now I need to add another twist to it. I need to add a TIMESTAMP and I can't get it to work. I have tried these below and none work. Any help would be greatly appreciated.
INSERT INTO `newslist_subscription` ( email, listid, since_date )
SELECT `email` , '1', 'TIMESTAMPE()'
FROM `customers` ;
INSERT INTO `newslist_subscription` ( email, listid, since_date )
SELECT `email` , '1', 'TIMESTAMPE'
FROM `customers` ;
INSERT INTO `newslist_subscription` ( email, listid, since_date )
SELECT `email` , '1', TIMESTAMPE()
FROM `customers` ;
PappaJohn
12-04-2008, 02:30 AM
It depends on how your since_date has been defined.
If it is of type DATETIME or TIMESTAMP use NOW().
If it is of type INT use UNIX_TIMESTAMP
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.