Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Speed query with rushmore index
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 5
Divers
Thread ID:
01202405
Message ID:
01202798
Vues:
13
>>>Yes, when you put a where condition on the LEFT joined table you would not get unmatched records and so it becomes an INNER JOIN.
>>>
>>>I was bitten few times (as I'm not that smart to learn from one trial), but now I know it.
>>
>>I don't think that is correct - the outer join does not become inner join when using where. You do get the unmatched records, but, of course, you get the unmatched recs only for the subset that meets the where conditions.
>>
create cursor C1 (pk i, fld2 l)
>>insert into C1 values (1,.t.)
>>insert into C1 values (2,.t.)
>>insert into C1 values (3,.f.)
>>create cursor C2 (pk i)
>>insert into C2 values (1)
>>insert into C2 values (3)
>
>>select C1.pk, C1.fld2, C2.pk as bpk from C1 left outer join C2 on C1.pk=C2.pk into cursor loj
>>select C1.pk, C1.fld2, C2.pk as bpk from C1 left outer join C2 on C1.pk=C2.pk where C1.fld2 into cursor lojw
>
>You're using where on the C1 field, not on C2 which is on the right side. Try
>
>create cursor C1 (pk i, fld2 l)
>insert into C1 values (1,.t.)
>insert into C1 values (2,.t.)
>insert into C1 values (3,.f.)
>create cursor C2 (pk i)
>insert into C2 values (1)
>insert into C2 values (3)
>select C1.pk, C1.fld2, C2.pk as bpk from C1 left outer join C2 on C1.pk=C2.pk into cursor loj
>select C1.pk, C1.fld2, C2.pk as bpk from C1 left outer join C2 on C1.pk=C2.pk where C1.fld2 into cursor lojw
>select C1.pk, C1.fld2, C2.pk as bpk from C2 left outer join C1 on C1.pk=C2.pk where C1.fld2 into cursor lojw2
>
>Notice, that I added one more record into C2.
>
>See also Re: Understanding LEFT JOIN Thread #1042886 Message #1042888
>and Re: Why this query doesn't return all Queue records? Thread #1078686 Message #1078700

I interpreted "put a where condition on the LEFT joined table" as "put a where condition on the table on the left in a left join"... I guess you can call any of he two tables as "left joined table".
OTOH, I didn't know that a where condition on the table on the right in a left join kills the outer join. It doesn't seem 100% right - what I expected was that you'll get a left join for the subsets defined by where conditions.
Doru
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform