select uf, mun_nome from pbx_municipio_classifica a, pbx_municipio_prefixo b where b.mun_id = a.mun_id and prx_prefixo = '653614' select * from pbx_municipio_prefixo where mun_id = 13400 insert into pbx_municipio_prefixo values(13400, '659289') select * from pbx_municipio_classifica where uf = 'MT' and mun_nome ilike '%CU%' select * from pbx_consulta_ddd limit 1 select * from pbx_municipios select distinct (select mun_id from pbx_municipio_classifica where uf = a.uf and mun_nome = a.nome_municipio and mun_ddd = a.codigo_ddd) as id, a.uf, a.nome_municipio, a.prefixo from pbx_consulta_ddd a where exists(select '' from pbx_municipio_classifica where uf = a.uf and mun_nome = a.nome_municipio and mun_ddd = a.codigo_ddd) delete from pbx_municipio_classifica --importa pbx_consulta_ddd insert into pbx_consulta_ddd select id, codigo_ddd, nome_municipio, uf, prefixo from pbx_municipios --importa pbx_municipio_classifica insert into pbx_municipio_classifica(uf, mun_nome, mun_ddd) select distinct uf, nome_municipio, codigo_ddd from pbx_municipios --importa prefixo insert into pbx_municipio_prefixo select distinct (select mun_id from pbx_municipio_classifica where uf = a.uf and mun_nome = a.nome_municipio and mun_ddd = a.codigo_ddd) as id, a.prefixo from pbx_consulta_ddd a where exists(select '' from pbx_municipio_classifica where uf = a.uf and mun_nome = a.nome_municipio and mun_ddd = a.codigo_ddd)