Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL with two JOINs
Message
De
04/02/2023 05:48:51
Lutz Scheffler
Lutz Scheffler Software Ingenieurbüro
Dresden, Allemagne
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
01686104
Message ID:
01686105
Vues:
40
>Hi,
>
>This is a very newbie question, I know.
>
>I am trying to understand the SQL Select that Tamar Granor kindly helped me with. It has two JOIN clauses. And THEN, after the second JOIN, there are two ON clauses. I didn't know you can do it. I thought that ON should follow the JOIN immediately.
>And looks like the first ON belong to the top (first) JOIN and the second ON belongs to the bottom (second) JOIN.
>
>My question is, how does SQL Server (or VFP for that matter) knows which ON apply to which JOIN?
>
>TIA

For all I know, there is the following syntax:

Syntax one: The ON follows the JOIN, from top to bottom
SELECT * ;
FROM Cur1 ;                     && - 
 INNER JOIN Cur2 ;              && - First Join	&& -
  ON Cur1.Field=Cur2.Field ;    && +            && |
 ;                                              && | Second Join (this is: to the result of the first)
 INNER JOIN Cur3 ;                              && -        && -
  ON Cur2.Field=Cur3.Field                      && +        && | ....
Syntax two: The ONs follows the JOINs, inside to outside
SELECT *;
 FROM Cur1;                                         && -
  INNER JOIN Cur2;              && -                && -
  INNER JOIN Cur3;              && - First Join     && |
  ON Cur2.Field=Cur3.Field;     && +                && | Second Join (this is: to the result of the first)
 ON Cur1.Field=Cur2.Field                           && +
You are free to mix the styles. It might create a headache, but is it possible.

Update: tab to space
Words are given to man to enable him to conceal his true feelings.
Charles Maurice de Talleyrand-Périgord

Weeks of programming can save you hours of planning.

Off

There is no place like [::1]
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform