Error in SQL statement

Asked

Viewed 63 times

2

I have the following comic: inserir a descrição da imagem aqui

When I run the following Query:

SELECT 
   tbCelula.*
FROM 
   (((tbTiposMonitorizacao 
INNER JOIN 
   tbMonitorizacaoProj ON tbTiposMonitorizacao.TM_ID = tbMonitorizacaoProj.MP_T_ID) 
INNER JOIN 
   tbListaConformidades ON tbMonitorizacaoProj.MP_ID = tbListaConformidades.L_MP_ID) 
 INNER JOIN 
   tbCelula ON tbTiposMonitorizacao.TM_ID = tbCelula.C_TM_ID) 
 INNER JOIN 
   tbValores ON (tbListaConformidades.L_ID = tbValores.V_L_ID) 
 AND 
   (tbCelula.C_ID = tbValores.V_C_ID)
WHERE 
   (((tbListaConformidades.L_ID)=21));

The instruction does not return to me all the data I belong to consult.

Output:

inserir a descrição da imagem aqui

Expected result:

inserir a descrição da imagem aqui

  • The V_ID column is a primary key, so it cannot be empty. Because in the expected result some fields are with the empty primary key?

1 answer

0


Probably when you run this

INNER JOIN  tbValores ON (tbListaConformidades.L_ID = tbValores.V_L_ID)

your select will only bring the records where tbListaConformidades.L_ID = tbValores.V_L_ID. Every time you do Inner Join, the query will only return where it has records in all tables. Test and add values to the blank records and you will see that they will appear in the query.
Example 1: we have a record where tbListaConformidades.L_ID = 7 but has no record where tbValores.V_L_ID = 7, then it will be discarded from the query and will go to the next.
Example 2: We have tbListaConformidades.L_ID = 3 and WE HAVE tbValores.V_L_ID = 7, ai yes will be printed on the return of the query.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.