Skip to content

Instantly share code, notes, and snippets.

@antunesleo
Last active March 8, 2017 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antunesleo/4e00a92874ee060f52fea9b8e2d5b645 to your computer and use it in GitHub Desktop.
Save antunesleo/4e00a92874ee060f52fea9b8e2d5b645 to your computer and use it in GitHub Desktop.
Arquivo contendo diversas queries de reconhecimento e exportação do banco de dados do projeto Nutrimep.
-- Seleciona o Alimento fazendo o join das tabelas com relacionamento
SELECT
a.*,
ga.nome AS grupo_alimentar_nome,
ta.nome AS tabela_alimentar_nome
FROM
alimento AS a
JOIN grupo_alimentar AS ga ON a.grupo_alimentar_id = ga.id
JOIN tabela_alimentar AS ta ON a.tabela_alimentar_id = ta.id
-- Seleciona a tabela alimento_nutriente fazendo os joins com as tabelas referênciadas
SELECT
an.*,
a.nome AS alimento_nome,
n.nome AS nutriente_nome
FROM
alimento_nutriente AS an
JOIN alimento AS a ON an.alimento_id = a.id
JOIN nutriente AS n ON an.nutriente_id = n.id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment