Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL Join with more than 2 tables
Message
De
09/01/2001 13:30:40
 
 
À
09/01/2001 12:09:30
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00461136
Message ID:
00461325
Vues:
15
>If I change your code to this as a nested Join.
>
>from TABLE1 ;
> join TABLE2 ;join TABLE3 ;
> join TABLE4 ;
> on TABLE1.FIELD1 = TABLE2.FIELD1 ;
> on TABLE2.FIELD2 = TABLE3.FIELD2 ;
> on TABLE3.FIELD3 = TABLE4.FIELD3
>

This won't work. When you have nested joins, the ONs are paired with the JOINs in reverse order. So, you'd need to write:

from TABLE1 ;
join TABLE2 ;
join TABLE3 ;
join TABLE4 ;
on TABLE3.FIELD3 = TABLE4.FIELD3 ;
on TABLE2.FIELD2 = TABLE3.FIELD2 ;
on TABLE1.FIELD1 = TABLE2.FIELD1

>1. Generally, how the SQL commad deal with nested jion and which Join do first, second and Third?

From a logical point of view, the innermost join is performed first. In the example, that's the join of Table3 and Table4. In VFP, the joins may actually be performed in a different order if the Rushmore engine decides that it's faster. I assume the same is true for other SQL engines, but I don't know it for sure.

If you want to know the order in which joins are occuring in VFP, use the SYS(3054) function. Execute SYS(3054,11) before your query and it'll show you all the optimization information.

>
>2. This code(I CHANGED) will get the same result like your original code?
>

As I said above, it won't work. You might get an error or you might get bad results. It depends what tables are open at the time you run the query.

Tamar
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform