Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to join 3 tables
Message
De
21/10/2003 19:25:19
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
 
 
À
21/10/2003 19:17:38
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00840872
Message ID:
00840894
Vues:
26
>>>>If you need to join the SECOND table to the third, the syntax becomes a little more involved; you have to insert stuff between the JOIN and ON, thusly:
>>>>
>>>>
>>>>sele a.pn ;
>>>>   from pnvendor a;
>>>>      left join inv b;
>>>>         left join Table3 on b.KeyField = Table3.KeyField;
>>>>      on a.pn = b.pn ;
>>>>   where [SomeCondition]
>>>>
>>>>
>>>>Note that I alligned the first LEFT and the last ON, to indicate they go together.
>>>>
>>>
>>>Actually, you don't have to.
>>
>>Yes, I know. Allignment is irrelevant for VFP. It helps the programmer keep things clear - and the reason I pointed this out is to indicate which commands go together. Understanding this can be important for more complicated queries.
>
>I mean you don't have to nest them. This works the same, and is easier to read.
>
>sele a.pn ;
>   from pnvendor a;
>      left join inv b on a.pn = b.pn ;
>      left join Table3 on b.KeyField = Table3.KeyField ;
>   where [SomeCondition]
>
This will join tables 1 and 2, and tables 1 and 3.

My second example joined tables 1 and 2, and tables 2 and 3.

I belive it is not always possible to re-arrange the order of the tables, especially when joining many tables. However, I would recommend joining a few pieces at a time - not for readability, but for speed.
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform