SELECT 
    m.entidad_id as ENTIDAD,
    e.nombre as MUNICIPIO,
    m.dpto_snc as DPTO_SNC,
    m.dist_snc as DIST_SNC
FROM public.snc_catalog_mapping m
LEFT JOIN LATERAL (
    SELECT nombre FROM dblink('host=192.168.1.254 user=postgres password=x25yvaga2017 dbname=sigemweb',
    'SELECT nombre FROM public.entidades WHERE entidad = ' || m.entidad_id)
    AS t(nombre text)
) e ON true
WHERE m.dpto_snc = 'H'
ORDER BY m.entidad_id;
