rleyba828
asked on
How to merge a mysql table into another without overwriting unique "key" fields.
Hi team,
I just need some assistance merging some old SSL certificates data ("OldCerts" table) into an SSL certificate master list ("Cert_Inventory_Master_Li st" table) but without overwriting records where the "CN" field and the "Cert_Expiry_Date" of the "OldCerts" table already exists on the "Cert_Inventory_Master_Lis t". In other words, I need to treat "CN"+"Cert_Expiry_Date" as a unique "key".
I'm not sure how to formulate the SQL statement below:
For clarity, here's the scenario.
* The idea is the two tables may have the same "CN" but if the expiry dates are different, then the merge should contain BOTH versions of the CN.
Thanks very much.
I just need some assistance merging some old SSL certificates data ("OldCerts" table) into an SSL certificate master list ("Cert_Inventory_Master_Li
I'm not sure how to formulate the SQL statement below:
INSERT INTO TABLE Cert_Inventory_Master_List (CN , Cert_Expiry_Date)
SELECT (CN, Cert_Expiry_Date) from OldCerts where ?????
For clarity, here's the scenario.
Cert_Inventory_Master_List table (before)
PRI_KEY CN Cert_Expiry_Date
1 certificate.a.com 2016-12-24
2 certificate.b.com 2016-12-25
3 certificate.c.com 2016-12-26
4 certificate.d.com 2016-12-27
OldCerts table
PRI_KEY CN Cert_Expiry_Date
1 certificate.a.com 2016-12-24
2 certificate.b.com 2016-11-11
3 certificate.d.com 2016-12-26
4 certificate.e.com 2016-12-27
Cert_Inventory_Master_List (after merge)
PRI_KEY CN Cert_Expiry_Date
1 certificate.a.com 2016-12-24
2 certificate.b.com 2016-12-25
3 certificate.c.com 2016-12-26
4 certificate.d.com 2016-12-27
5 certificate.b.com 2016-11-11
6 certificate.d.com 2016-12-26
7 certificate.e.com 2016-12-27
* The idea is the two tables may have the same "CN" but if the expiry dates are different, then the merge should contain BOTH versions of the CN.
Thanks very much.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Open in new window
Thanks very much.