Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to join 3 tables
Message
From
21/10/2003 18:43:31
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
 
To
21/10/2003 18:35:21
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00840872
Message ID:
00840875
Views:
20
>hello everybody
>
>i have 3 tables i need to join
>pnvendor
>inv
>vendor
>i am able to join the first 2 tables
>sele a.pn ;
>   from pnvendor a left join inv b on a.pn = b.pn ;
>   where ;
>      "1004" $ a.vendorid .and. ;
>      "04AV205" $ a.pn
>how do i add the 3rd table. the 3rd table (vendor) needs to be joint to the 1st table (pnvendor) on the vendorid field in the same way the 1st and the 2nd table are joint.
>
>thank for all your help as always!

That would be something like this:
sele a.pn ;
   from pnvendor a;
      left join inv b on a.pn = b.pn ;
      left join vendor on a.keyfield = vendor.keyfield;
   where ;
      "1004" $ a.vendorid .and. ;
      "04AV205" $ a.pn
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.

HTH,

Hilmar.
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)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform