Inner John and Left John problem

Asked

Viewed 94 times

0

I am using the Postgresql + C database#

I have a Type that we can call Main. Inside it I have a long id, string name, I have a Classea, Classeb, Classec. Both the Classea, Classeb, Classec may or may not be filled then to perform the query I use the LEFT JOIN and do the query without problem.

Now within Classea I have Classezz, it is a class that I need to search with Classea, so to do this I use INNER JOIN, so I bring the information from Classezz to be filled inside Classea

Now the problem: how in this query the Classea data can return null, and when this occurs, is not returning a single line, since I have an Inner Join between Classea and Classezz. If I modify this Inner Join between Classea and Classezz I get the data without problems.

there is the question: is it possible to do this query in a single SQL query? or I will have to split in two?

EDIT: or having to do a "gambiarra" and leave all table junctions as LEFT JOIN?

EDIT2: Follows SQL code:

SELECT at_customer service.Customer service at_customer service, at_call.Date AS at_call, at_service.closed AS at_service closed, at_service.transmitted AS at_service transmitted, at_attendance.Id AS at_attendance_Id, at_attendance_cad_cliente_cartao_cad_client.Document AS at_attendance_cad_cliente_cartao_cad_cliente_Document, at_attendance_cad_cliente_cartao_cad_client.Document2 AS at_attendance_cad_cliente_cartao_cad_cliente_Document2, at_attendance_cad_cliente_cartao_cad_client.Razaosocial AS at_attendance_cad_cliente_cartao_cad_cliente_RazaoSocial, at_attendance_cad_cliente_cartao_cad_client.Namespace AS at_attendance_cad_cliente_cartao_cad_cliente_NomeFantasia, at_attendance_cad_cliente_cartao_cad_client.Cep AS at_attendance_cad_cliente_cartao_cad_cliente_Cep, at_attendance_cad_cliente_cartao_cad_client.Address_at_attendance_cad_cliente_cartao_cad_cliente_Endereco, at_attendance_cad_cliente_cartao_cad_client.Numero AS at_attendance_cad_cliente_cartao_cad_cliente_Numero, at_attendance_cad_cliente_cartao_cad_client.Complement AS at_attendance_cad_cliente_cartao_cad_cliente_Complemento, at_attendance_cad_cliente_cartao_cad_client.Neighborhood AS at_attendance_cad_cliente_cartao_cad_cliente_Bairro, at_attendance_cad_cliente_cartao_cad_client.City AS at_attendance_cad_cliente_cartao_cad_cliente_City, at_attendance_cad_cliente_cartao_cad_client.Status AS at_attendance_cad_cliente_cartao_cad_cliente_State, at_attendance_cad_cliente_cartao_cad_client.Ramoprincipal AS at_attendance_cad_cliente_cartao_cad_cliente_RamoPrincipal, at_meeting_cad_cliente_cartao_cad_client.Tel1 AS at_meeting_cad_cliente_cartao_cad_cliente_Tel1, at_attendance_cad_cliente_cartao_cad_client.Ramal1 AS at_attendance_cad_cliente_cartao_cad_cliente_Ramal1, at_meeting_cad_cliente_cartao_cad_client.Tel2 AS at_meeting_cad_cliente_cartao_cad_cliente_Tel2, at_attendance_cad_cliente_cartao_cad_client.Ramal2 AS at_attendance_cad_cliente_cartao_cad_cliente_Ramal2, at_meeting_cad_cliente_cartao_cad_client.Isemiteboleto AS at_meeting_cad_cliente_cartao_cad_cliente_IsEmiteBoleto, at_servimento_cad_cliente_cartao_cad_client.Tipodocumento AS at_servimento_cad_cliente_cartao_cad_cliente_TipoDocument, at_attendance_cad_cliente_cartao_cad_client.Authorizingolancamento AS at_attendance_cad_cliente_cartao_cad_cliente_AutorizacaoLancamento, at_attendance_cad_cliente_cartao_cad_client.Id AS at_attendance_cad_cliente_cartao_cad_cliente_Id, at_attendance_cad_cliente_card.Card AS at_attendance_cad_cliente_card, at_attendance_cad_cliente_card.Administrative code AS at_attending_cad_cliente_cartao_CodigoAdministrative, at_attendance_cad_cliente_card.Contract AS at_attendance_cad_cliente_card, at_service_cad_cliente_card.Validity AS at_service_cad_cliente_cartao_Validade, at_attendance_cad_cliente_card.Sigepuser AS at_attendance_cad_cliente_cartao_SigepUser, at_attendance_cad_cliente_card.Sigepsenha AS at_attendance_cad_cliente_cartao_SigepNewing, at_attending_cad_cliente_card.Description AS at_attending_cad_cliente_card, at_attendance_cad_cliente_card.deactivated AS at_attendance_cad_cliente_card deactivated, at_attending_cad_cliente_card.Id AS at_attending_cad_cliente_cartao_Id FROM at_atendimento AS at_atendimento LEFT JOIN cad_cliente_cartao AS at_attendance_cad_cliente_cartao ON at_attendance_cad_cliente_cartao.Id = at_atendimento.cad_cliente_cartao_id JOIN cad_client AS at_attendance_cad_cliente_cartao_cad_client ON at_attendance_cad_cliente_cartao_cad_client.Id = at_attendance_cad_cliente_cartao.cad_cliente_id

  • You have to know how your database tables are organized and then use the specific merge type for what you want to get as a result of the query.

  • Instead of trying to describe, present your code and structure of truth so that the question makes sense and you have a [mcve]

  • follow SQL code, I apologize for the delay, the data was in the company

  • "Now inside Classea I have Classezz, it is a class that I need to search with Classea, so to do this I use INNER JOIN, so I bring the information from Classezz to be filled inside Classea Now the problem: as in this query Classea data can return null, and when this occurs, it is not returning a single line, since I have an Inner Join between Classea and Classezz. If I modify this Inner Join between Classea and Classezz I get the data without problems." to which type of merge modification you refer?

  • is not modification, is a select, need to bring the information and if I use a Join Inner in the class left Join, if that class which is left Join for null, it returns nothing

  • "If I modify this Inner Join between Classea and Classezz"?

  • Are you trying to give a Join on the same table??? o.0

Show 2 more comments

1 answer

0

I have dealt with a very similar problem. Follow this image here. I believe that one of the 3 on the right is exactly what you want. In the Where clause you put the null condition (in the case Dbnull)Olhe essa imagem

  • that part I even know, now and if I have a column C right after the B that is INNER JOIN being that B is LEFT JOIN if B is null no row is loaded that is my problem

Browser other questions tagged

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