Query with Join returning empty

0

Please help me check my query because it is giving an error that I can not identify.  If I do the simple query:

 SELECT 
    *
       FROM 
         respostas 
                   WHERE 
                     resp_usuario='8'
                    AND  resp_questionario='6' 

Returns the results normally, but if I insert a join it does not return anything, it follows the Join query:

SELECT 
     q.quest_nome                    AS QUESTIONARIO,
     u.usu_id                        AS ID_USUARIO,
     u.usu_nome                      AS USUARIO,
     l.loja_id                       AS END,
     a.area_desc                     AS SETOR,
     sb.sub_area_nome                AS SUBAREA,
     p.perg_desc                     AS PERGUNTA,
     r.resp_resposta                 AS RESPOSTA,
     p.perg_peso                     AS PESO,
     (p.perg_peso * r.resp_resposta) AS PONDERADA,
     (p.perg_peso * 5)               AS MAXIMO,
     (p.perg_peso * r.resp_resposta / (p.perg_peso * 5)*100)PERCENTUAL
       FROM 
         respostas AS r
         INNER JOIN questionario AS q  ON r.resp_questionario = q.quest_id
         INNER JOIN usuarios     AS u  ON r.resp_usuario      = u.usu_id
         INNER JOIN lojas        AS l  ON r.resp_loja         = l.loja_id
         INNER JOIN area         AS a  ON r.resp_area         = a.area_id
         INNER JOIN sub_area     AS sb ON r.resp_subgrupo     = sb.sub_area_cod
         INNER JOIN perguntas    AS p  ON r.resp_pergunta_id  = p.perg_id
                     WHERE 
                       r.resp_usuario='8'
                       AND r.resp_questionario='6'

What could I be doing wrong?

Att,

    
asked by anonymous 06.04.2016 / 16:54

1 answer

0

I was able to get the result as indicated by @rray.

Thank you.

SELECT 
         q.quest_nome                    AS QUESTIONARIO,
         u.usu_id                        AS ID_USUARIO,
         u.usu_nome                      AS USUARIO,
         l.loja_id                       AS END,
         a.area_desc                     AS SETOR,
         sb.sub_area_nome                AS SUBAREA,
         p.perg_desc                     AS PERGUNTA,
         r.resp_resposta                 AS RESPOSTA,
         p.perg_peso                     AS PESO,
         (p.perg_peso * r.resp_resposta) AS PONDERADA,
         (p.perg_peso * 5)               AS MAXIMO,
         (p.perg_peso * r.resp_resposta / (p.perg_peso * 5)*100)PERCENTUAL
           FROM 
             respostas AS r
             LEFT JOIN questionario AS q  ON r.resp_questionario = q.quest_id
             LEFT JOIN usuarios     AS u  ON r.resp_usuario      = u.usu_id
             LEFT JOIN lojas        AS l  ON r.resp_loja         = l.loja_id
             LEFT JOIN area         AS a  ON r.resp_area         = a.area_id
             LEFT JOIN sub_area     AS sb ON r.resp_subgrupo     = sb.sub_area_cod
             LEFT JOIN perguntas    AS p  ON r.resp_pergunta_id  = p.perg_id
                         WHERE 
                           r.resp_usuario='8'
                           AND r.resp_questionario='6'
    
14.04.2016 / 20:51