Select from two tables

Dúvidas, dicas e truques de SQL, Select, Update, Delete, cláusulas, operações com joins, Funções em SQLs, etc
  

Poston Mon, 05 May 2008 11:14 am

I have two tables tbl_requisicao_grid tbl_conta_morador_item items in tbl_requisicao_grid may or may not have também on tbl_conta_morador_item, depends on if she enters the monthly closing ... I can't do a select that behind what exists in one and exist on another.

How do I do a select to get the records you have in your tbl_requisicao_grid and not on tbl_conta_morador_item they are linked by the cod_tbl_requisicao tbl_requisicao_grid = cod_tbl_requisicao tbl_conta_morador_item = cod_requisicao anyone know how to make the comparison and bring what you have in one and the other not?

vlw
dante
Location: sao paulo sp

Danilo Maranini
Aprendendo e Compartilhando

Poston Mon, 05 May 2008 5:00 pm

well, with me on one occasion like these two options saved me
Code: Select all
select tr.*
  from tbl_requisicao_grid tr
where not exists ( select 1
                      from tbl_conta_morador_item ti
                     where tr.cod_tbl_requisicao = ti.cod_requisicao)

select tr.*
  from tbl_requisicao_grid tr
where tr.cod_tbl_requisicao not in (select ti.cod_requisicao
                                       from tbl_conta_morador_item ti)
in my case the performance gain of the second option was better .... I don't know how it's going to be for you, depends of the Indexes.
gokden
Location: Ribeirão Preto - SP

Lucas de Souza

OCA Developer
Analista de sistemas

Poston Thu, 08 May 2008 9:37 am

lucas!

muito thanks dude!!!

I'll test this select only on Monday ... then put a return here ... thanks for the attention hugs
dante
Location: sao paulo sp

Danilo Maranini
Aprendendo e Compartilhando



Return to SQL

Who is online

Users browsing this forum: No registered users and 5 guests