Ajuda para decifrar linhas de código
15/02/2007
0
Boa tarde:
Alguém poderia ajudar-me com as linhas abaixo, ou seja, o que cada linha quer dizer. Tenho dificuldades em saber sobre left e in. Se alguém puder tirar essas dúvidas.
SELECT G.ID_GRUPO_PAI, COALESCE(GP.DESCRICAO, ´´) DESCRICAO_GRUPO_PAI,
G.ID_GRUPO_RELATORIOS, G.DESCRICAO, G.PROTEGIDO
FROM GRUPOS_RELATORIOS G
LEFT JOIN GRUPOS_RELATORIOS GP ON GP.ID_GRUPO_RELATORIOS = G.ID_GRUPO_PAI
WHERE G.ID_GRUPO_RELATORIOS
IN (SELECT R.ID_GRUPO_RELATORIOS FROM RELATORIOS R WHERE R.TIPO_RELATORIO <> 2)
OR G.ID_GRUPO_RELATORIOS IN (SELECT G2.ID_GRUPO_PAI FROM GRUPOS_RELATORIOS G2)
ORDER BY G.ID_GRUPO_PAI, G.DESCRICAO
Alguém poderia ajudar-me com as linhas abaixo, ou seja, o que cada linha quer dizer. Tenho dificuldades em saber sobre left e in. Se alguém puder tirar essas dúvidas.
SELECT G.ID_GRUPO_PAI, COALESCE(GP.DESCRICAO, ´´) DESCRICAO_GRUPO_PAI,
G.ID_GRUPO_RELATORIOS, G.DESCRICAO, G.PROTEGIDO
FROM GRUPOS_RELATORIOS G
LEFT JOIN GRUPOS_RELATORIOS GP ON GP.ID_GRUPO_RELATORIOS = G.ID_GRUPO_PAI
WHERE G.ID_GRUPO_RELATORIOS
IN (SELECT R.ID_GRUPO_RELATORIOS FROM RELATORIOS R WHERE R.TIPO_RELATORIO <> 2)
OR G.ID_GRUPO_RELATORIOS IN (SELECT G2.ID_GRUPO_PAI FROM GRUPOS_RELATORIOS G2)
ORDER BY G.ID_GRUPO_PAI, G.DESCRICAO
Oziasl
Curtir tópico
+ 0
Responder
Posts
11/10/2007
Joni Nunes
Boa tarde, primeiramente recomendo a você que faça a leitura de livros sobre banco de dados, específicamente sobre suas dúvidas, o ideal é que leia todo o conteúdo.
Quanto a sua resposta, segue em AZUL uma pequena explicação.
Abraço.
SELECT G.ID_GRUPO_PAI, COALESCE(GP.DESCRICAO, ´´) DESCRICAO_GRUPO_PAI,
G.ID_GRUPO_RELATORIOS, G.DESCRICAO, G.PROTEGIDO
[color=blue:1f07950116]selecione os campos ID_GRUPO_PAI, DESCRICAO_GRUPO_PAI[/color:1f07950116]
FROM GRUPOS_RELATORIOS G
[color=blue:1f07950116]das tabelas GRUPOS_RELATORIOS que ele da um ALIAS ( codenome para a tabela para reduzir a escrita em muitos casos ) G[/color:1f07950116]
LEFT JOIN GRUPOS_RELATORIOS GP ON GP.ID_GRUPO_RELATORIOS = G.ID_GRUPO_PAI
[color=blue:1f07950116]fazendo união entre as tabelas GRUPO_PAI, chamada de GP e a tabela [/color:1f07950116]GRUPOS_RELATORIOS chamada de G
WHERE G.ID_GRUPO_RELATORIOS
[color=blue:1f07950116]onde atenda a condição de que o código G.ID_GRUPO_RELATORIOS exista em uma determinada consulta SQL, uma listagem conforme o SQL abaixo.[/color:1f07950116]
IN (SELECT R.ID_GRUPO_RELATORIOS FROM RELATORIOS R WHERE R.TIPO_RELATORIO <> 2)
OR G.ID_GRUPO_RELATORIOS IN (SELECT G2.ID_GRUPO_PAI FROM GRUPOS_RELATORIOS G2)
ORDER BY G.ID_GRUPO_PAI, G.DESCRICAO
[color=blue:1f07950116]ordena a listagem por código ID_GRUPO_PAI e descrição do grupo G.DESCRICAO[/color:1f07950116]
Quanto a sua resposta, segue em AZUL uma pequena explicação.
Abraço.
SELECT G.ID_GRUPO_PAI, COALESCE(GP.DESCRICAO, ´´) DESCRICAO_GRUPO_PAI,
G.ID_GRUPO_RELATORIOS, G.DESCRICAO, G.PROTEGIDO
[color=blue:1f07950116]selecione os campos ID_GRUPO_PAI, DESCRICAO_GRUPO_PAI[/color:1f07950116]
FROM GRUPOS_RELATORIOS G
[color=blue:1f07950116]das tabelas GRUPOS_RELATORIOS que ele da um ALIAS ( codenome para a tabela para reduzir a escrita em muitos casos ) G[/color:1f07950116]
LEFT JOIN GRUPOS_RELATORIOS GP ON GP.ID_GRUPO_RELATORIOS = G.ID_GRUPO_PAI
[color=blue:1f07950116]fazendo união entre as tabelas GRUPO_PAI, chamada de GP e a tabela [/color:1f07950116]GRUPOS_RELATORIOS chamada de G
WHERE G.ID_GRUPO_RELATORIOS
[color=blue:1f07950116]onde atenda a condição de que o código G.ID_GRUPO_RELATORIOS exista em uma determinada consulta SQL, uma listagem conforme o SQL abaixo.[/color:1f07950116]
IN (SELECT R.ID_GRUPO_RELATORIOS FROM RELATORIOS R WHERE R.TIPO_RELATORIO <> 2)
OR G.ID_GRUPO_RELATORIOS IN (SELECT G2.ID_GRUPO_PAI FROM GRUPOS_RELATORIOS G2)
ORDER BY G.ID_GRUPO_PAI, G.DESCRICAO
[color=blue:1f07950116]ordena a listagem por código ID_GRUPO_PAI e descrição do grupo G.DESCRICAO[/color:1f07950116]
Responder
Clique aqui para fazer login e interagir na Comunidade :)