Hola amigos buena noche:
Quisiera realizar pedirles por favor de su apoyo para resolver la siguiente necesidad:
Tengo dos tablas:
Código:
CREATE TABLE
type1
(
id_type INT NOT NULL AUTO_INCREMENT,
type VARCHAR(50),
id_vers INT,
date_type TIMESTAMP,
PRIMARY KEY (id_type, date_type)
)
ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE
type2
(
id_type INT NOT NULL AUTO_INCREMENT,
type VARCHAR(50),
id_vers INT,
date_type TIMESTAMP,
PRIMARY KEY (id_type, date_type)
)
ENGINE=InnoDB DEFAULT CHARSET=utf8;
Como veran son dos tablas identicas, la diferencia que hay es que en la segunda tabla type2 hay datos que no hay en la tabla primera (type1). Necesito obtener los valores que no estan en la tabla (type1) e insertarlos en esa misma tabla.
La consulta que he intentado realizar es la siguiente pero no he tenido éxito:
Código:
INSERT INTO type1
SELECT *
FROM type2 AS t1
left join type1 AS t2 on t1.type=t2.type AND t1.id_vers=t2.id_vers
Por ejemplo
type1
Código:
id type id_vers date_type
1 Americano 1 2014-10-03 17:55:14
2 Frances 1 2014-10-03 17:56:00
3 Asatico 2 2014-10-03 17:57:00
type2
Código:
id type id_vers date_type
1 Americano 1 2014-10-03 17:55:00
2 Frances 1 2014-10-03 17:56:00
3 Asatico 2 2014-10-03 17:57:00
4 Africano 1 2014-10-03 17:58:00
5 Europeo 3 2014-10-03 17:59:00
Como se puede observar los datos de la tabla type2 con id 4 y 5 no estan en la primera tabla, estos son los que quisiera obtenerlos e insertarlos en la tabla type1.
De antemano gracias por su tiempo y atención...
Saludos