1
Complementing with current information, I understood the current result, and what it seems is duplicated information even, but in different tables, but this is not even with me because I already arrived and was like this and I’m still an intern I’m just studying this bank. I’m still trying to better understand the use of JOINS.
===========================================================
I’m trying to make an appointment the following way:
SELECT p.idPessoa AS ID_PESSOA,
p.nome AS TITULAR,
d.idDependente AS ID_DEPENDENTE,
d.nome AS DEPENDENTE,
c.valorAuxilio AS VALOR_AUXILIO
FROM sca_pessoa p
INNER JOIN sca_dependente d ON p.idPessoa = d.idPessoa
INNER JOIN sispro_contrato c ON p.idPessoa = c.idPessoa
WHERE p.nome LIKE '%ADEMAR MAGA%' AND c.idSituacaoContrato = 3 AND c.valorAuxilio IS NOT NULL;
I would like it to have the following result: NAME HOLDER, NAME DEPENDENT and VALUE OF ASSISTANCE that would be the value of each one (2x persons) as shown in the table below.
The name table sispro_contract has the values as shown below:
What would be wrong or missing?
If I take the AND c.valorAuxilio <> null the return stays like this:
Follow the structures of the tables:
sca_pessoa
idPessoa int(10) unsigned
matricula varchar(45)
nome varchar(100)
telefoneResidencial char(13)
telefoneCelular char(13)
telefoneUnidade char(13)
email varchar(100)
dtAdmissao date
dtNascimento date
idSituacao int(4)
SalarioReferencia int(10) unsigned
idCargo int(10)
idLotacao int(11)
cpf varchar(45)
codigoLotacao varchar(45)
funcaoValorInicialVertical varchar(45)
funcaoValorInicialHorizontal varchar(45)
idFuncao int(11) unsigned
sexo char(1)
rg varchar(15)
nomePai varchar(44)
nomeMae varchar(44)
gsanguineo varchar(3)
rh varchar(3)
ativo char(1)
sca_dependente
idDependente int(10) unsigned
idPessoa int(11) unsigned
nome varchar(100)
dtNascimento date
idParentesco int(11) unsigned
pensionista tinyint(3) unsigned
universitario tinyint(3) unsigned
pne tinyint(3) unsigned
comprovanteEscolar tinyint(3)
sispro_contrato
idContrato int(10) unsigned
idOperadora int(10) unsigned
proposta varchar(45)
ans varchar(45)
valor decimal(10,2)
idPessoa int(10) unsigned
idFormaDePagamento int(10) unsigned
idSituacaoContrato int(10) unsigned
idOperadorUltimaAtualizacao varchar(45)
dataContrato date
dataEncaminhamento date
dataDeferimento date
dataHoraUltimaAlteracao datetime
dataRequerimento date
dataSituacaoAtual date
dataSuspensao date
dataCancelamento date
idProcesso int(11) unsigned
valorAuxilio decimal(10,2)
idDependente int(10) unsigned
idOperador varchar(45)
idTipoOperadora int(10) unsigned
valorTotalAuxilio decimal(10,2)
Note that it was not that the above QUERY does not return anything, and what I wanted to return would be only NAME, DEPENDENT and VALUE HELP that would be these last two.
– phpricardo
I believe you’re doing the
inner join
in the wrong way.– Beterraba
@Bacco would like to ask you just one thing about using JOINS, which I did not understand well and I was in doubt. The use of JOINS will be applied only in the tables that have a relationship, that is, a PK for a FK, or simply between two PK, which does not make sense in fact. So when I use ... ON Taba.idPessoa = Tabb.idPessoa(Which is a FK) it’s like this?
– phpricardo
@phpricardo If this is the case to remove Accept from my answer, I see no problems, since the problem is not solved, but anyway I think it is good to isolate each part of the problem and clarify the doubt. So far I don’t think I can understand how you want the two lines to disappear, since they are in the database so everything indicates.
– Bacco
The ON of Join is to say under what conditions the two columns will appear in the same result. You came to see this link? What is the difference between Ner Join and Uter Join
– Bacco
Yes, but I don’t understand this question of mine.
– phpricardo
@phpricardo if there are two lines per person, it may be a problem in the Join or in the database. Does this Ademar not really have two different contracts for these two people? It would be good for you to raise all these questions. How should it appear? What is the right one, the Cícera of 109 or the 269? Is it to add the values, or is it to take just one of them? If it is only one, which one?
– Bacco
@phpricardo one thing that could be really wrong is the ON. Post the structure of the tables, suddenly we are not able to notice something because of it. Maybe the correct ID is not the idPersonal on both sides
– Bacco
It’s a bit big @Bacco I can put the table desc right here?
– phpricardo
Here you can download https://copy.com/UCMoq8uJx24g
– phpricardo
@phpricardo Whenever you post in code format, when it is long it appears scrollbar. But as link already helps.
– Bacco
Even reading the two questions, it’s still unclear what you want. Please edit the question with the expected output.
– bfavaretto
@phpricardo, I think you still don’t have it clear: the network [if] is very different of the traditional forums. Here, "solved" is the answer marked as correct by the author of the question, and the "utility" is for all internet. Once you publish your problem here, it is no longer "yours". So be careful with your company code and license
cc by sa
that all material posted here automatically wins.– brasofilo