--insert into atencion_ciudadana_estado select * from estado select * from atencion_ciudadana_estado --insert into atencion_ciudadana_municipio select id, nombre, estado_id from municipios where estado_id = 27 select * from atencion_ciudadana_municipio --insert into atencion_ciudadana_localidad select * from localidad select * from atencion_ciudadana_localidad /* select * from municipios where estado_id = 27; select * from atencion_ciudadana_lugar b where b.padre_id = 51 and b.id < 100; select a.* , 'update municipios set id_referencia = '|| b.id ||' where id = '|| a.id ||';--'||b.nombre , b.nombre, b.id from municipios a inner join atencion_ciudadana_lugar b on a.estado_id = 27 and b.padre_id = 51 and b.id < 100; update municipios set id_referencia = 61 where id = 4419; update municipios set id_referencia = 67 where id = 4420; update municipios set id_referencia = 69 where id = 4421; update municipios set id_referencia = 52 where id = 4422; update municipios set id_referencia = 55 where id = 4423; update municipios set id_referencia = 68 where id = 4424;--Cunduacán update municipios set id_referencia = 60 where id = 4425;--Emiliano zapata" update municipios set id_referencia = 66 where id = 4426;--Huimanguillo" update municipios set id_referencia = 63 where id = 4427;--Jalapa" update municipios set id_referencia = 62 where id = 4428;--Jalpa de mendez" update municipios set id_referencia = 73 where id = 4429;--Jonuta" update municipios set id_referencia = 56 where id = 4430;--Macuspana" update municipios set id_referencia = 65 where id = 4431;--Nacajuca" update municipios set id_referencia = 70 where id = 4432;--Paraiso" update municipios set id_referencia = 72 where id = 4433;--Tacotalpa" update municipios set id_referencia = 71 where id = 4434;--Teapa" update municipios set id_referencia = 64 where id = 4435;--Tenosique" select a.*, b.* from municipios a inner join atencion_ciudadana_lugar b on a.id_referencia = b.id; select * from localidad a inner join municipios b on a.municipio_id = b.id; SELECT * FROM ATENCION_CIUDADANA_LUGAR A right join localidad b on lower(a.nombre) = lower(b.nombre) and a.padre_id= 51 and b.municipio_id = (select id from municipios where id_referencia = a.id) order by 1 ; */