Information générale
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
>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
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement