Skip to content

Instantly share code, notes, and snippets.

@alfredoem
Created May 16, 2019 17:00
Show Gist options
  • Save alfredoem/5dda432e7d9a30dd6bdfe1fa8d182008 to your computer and use it in GitHub Desktop.
Save alfredoem/5dda432e7d9a30dd6bdfe1fa8d182008 to your computer and use it in GitHub Desktop.
Outer Join Mysql
SELECT
u.nombre,
ine.departamento,
ine.provincia,
ine.distrito
FROM mod_ubigeo_departamento AS u
LEFT JOIN ubigeo_inei AS ine ON UPPER(u.nombre) = UPPER(ine.departamento)
WHERE ine.departamento IS NULL
GROUP BY u.nombre
UNION
SELECT
u.nombre,
ine.departamento,
ine.provincia,
ine.distrito
FROM mod_ubigeo_departamento AS u
RIGHT JOIN ubigeo_inei AS ine ON UPPER(u.nombre) = UPPER(ine.departamento)
WHERE u.nombre IS NULL
GROUP BY u.nombre;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment