well
I need to select everything from table Pessoa where idUnidade from table Unidade be equal to 17
if somebody understands my question please help me
thanks in advance
Last edited by Daskalos; Apr 11th, 2005 at 04:27 PM.
[vbcode]Dim Daskalos As NewBie
If My.english = Wrong Then
Forgive My.Poor.English
End If[/vbcode] Ða§kalø§
ICQ#: 36146307
Current ICQ status: More ways to contact me
Select * From Pessoa
Where idPessoa in (Select idPessoa From AreaPessoa
Left Join Area on Area.idArea=AreaPessoa.idArea
Where idUniDade=17)
hum.. it worked.. i after I saw you first post, i did this:
Code:
Select * From Pessoa
Where idpessoa in (Select idpessoa From AreaPessoa Where idarea in
(SELECT idarea FROM area where idunidade = 17))
i don't know why, but i think you code is better
so.. could you explain me how does this "Left Join" works??
Last edited by Daskalos; Apr 11th, 2005 at 04:05 PM.
[vbcode]Dim Daskalos As NewBie
If My.english = Wrong Then
Forgive My.Poor.English
End If[/vbcode] Ða§kalø§
ICQ#: 36146307
Current ICQ status: More ways to contact me
Not knowing much about the data in your tables - it's probably better yet to do this:
Code:
Select * From Pessoa
Where idPessoa in (Select idPessoa From AreaPessoa
Left Join Area on Area.idArea=AreaPessoa.idArea
Where idUniDade=17
Group by idPessoa)
The GROUP BY will make sure that the "sub-query" recordset is as small as possible.
The LEFT JOIN is creating a "single working table" from both the idPessoa and Area tables - all columns from both tables will be JOINED as if one table - on the criteria shown in the ON clause of the LEFT JOIN.
I use LEFT JOIN instead of JOIN as a habit since we have so much legacy data that we've converted from mainframes. The relationships are not always clean. JOIN will throw away the "primary" table row (in the FROM clause) if the JOIN table sister row does not exist. LEFT JOIN will not do that - the "primary" table row comes through, but the columns from the JOINED table for that row will be NULL.
*** Read the sticky in the DB forum about how to get your question answered quickly!! ***
Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".
[vbcode]Dim Daskalos As NewBie
If My.english = Wrong Then
Forgive My.Poor.English
End If[/vbcode] Ða§kalø§
ICQ#: 36146307
Current ICQ status: More ways to contact me