0
I’m trying to make a select on these two tables, but this bringing wrong data, I want to do the following, list the loan requests that have not yet been rented, ie if the codigo_socio
within the loaned table it is not shown to the user and lists the remainder of requests that are not in the loaned table but in the solicitaçãoemprestimo
.
EMPRESTADOS
codemprestados
dataemprestimo
horaemprestimo
solicitacaoemprestimo_socio_codigo
SOLICITACAOEMPRESTIMO
codemprestimo
dataemprestimo
horaemprestimo
socio_codigo
I’m trying to do it like this:
select se.* from solicitacaoemprestimo se
left join emprestados e on e.solicitacaoemprestimo_socio_codigo = se.socio_codigo
where e.solicitacaoemprestimo_socio_codigo = '41';
But this bringing field that is inside the borrowed, I wanted you not to bring the item but to filter what is already on the borrowed table. Already I thank you.
So let’s say that in the loan application I have three requests, then I sent one to the borrowed table, when I list I want to appear only the items that are not within the borrowed table, as I lent would have to appear only two items.
– Carlos Leandro Ferreira de Alm
In this example I tried and it brings nothing.
– Carlos Leandro Ferreira de Alm
@Carlosleandroferreiradealm I changed here again. The column
codemprestimo
is the same ascodemprestados
of Lent?– Maicon Carraro
I updated SELECT with this column.
– Maicon Carraro
No, it’s not, but I need to bring by the partner’s code, by the codemprestimo I got too.
– Carlos Leandro Ferreira de Alm
@Carlosleandroferreiradealm That’s not just for doing
where e.codemprestados is null AND se.socio_codigo = '41'
?– Maicon Carraro
then, like: select if. * from solicitacaoemprestimo se left Join lent e on.codemprestados = se.codemprestimo Where e.codemprestados is null AND se.socio_codigo = '41' ; it brings what is inside the borrowed one I need it to bring in the ones that are not borrowed.
– Carlos Leandro Ferreira de Alm
From the moment you do
e.codemprestados is null
It will only bring what it does not have on the table borrowed, if it is bringing wrong may be incorrect data in the table. Put an example on Sqlfiddle for us to check– Maicon Carraro
what is a sqlFiddle?
– Carlos Leandro Ferreira de Alm
@CarlosLeandroFerreiradeAlm http://sqlfiddle.com/
– Maicon Carraro
On the left side you place the create table and Inserts (do some Inserts that exist in your bank) and on the right side will select
– Maicon Carraro
I’ve already done it and it only brings what’s inside the borrowed table.
– Carlos Leandro Ferreira de Alm
then I changed a parameter and it worked. It looked like this: select if. * from solicitacaoemprestimo se left Join lent e on.solicitacaoemprestimo_codemprestimo = se.codemprestimo Where e.codemprestados is null AND se.socio_codigo = '41';
– Carlos Leandro Ferreira de Alm
changed this part of the code: on e.requecamprestimo_codemprestimo = se.codemprestimo
– Carlos Leandro Ferreira de Alm
Thanks Maicon, thank you!
– Carlos Leandro Ferreira de Alm
True, I hadn’t noticed that, I’m glad it worked out :)
– Maicon Carraro
@Carlosleandroferreiradealm I updated my answer with the error you found.
– Maicon Carraro