Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL 1 Parent many children
Message
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00412522
Message ID:
00412555
Vues:
26
>>I have 1 main parent table to many children tables. However, the children are related only to the parent not to each other. That is, there is no grandchild tables. I wanted to put all tables used in to a single SQL like:
>>SELECT MyParent.* ;
>>FROM MyParent, MyChild1, MyChild2, MyChild3 ;
>>INNER JOIN MyChild1 ;
>>INNER JOIN MyChild2 ;
>>INNER JOIN MyChild3 ;
>>ON MyParent.MyKey = MyChild3.MyKey ;
>>ON MyParent.MyKey = MyChild2.MyKey ;
>>ON MyParent.MyKey = MyChild1.MyKey ;
>>WHERE MyParent.MyField1 = "MyVal" ;
>>AND MyChild1.MyField = "MyVal" ;
>>AND MyChild2.MyField = "MyVal" ;
>>AND MyChild3.MyField = "MyVal"
>>However SYS(3054,11) shows cartesians are being processed after the first join. Is there any way to join these tables in one SQL statement or do I have to buiild them (or is it more efficient) one table at a time to a preceeding result set?
>>Thanks
>
>John,
>
>Just from curiosity: Does this slight modification help?
>
SELECT MyParent.* ;
    FROM MyParent ;
    INNER JOIN MyChild1 ;
    ON MyParent.MyKey = MyChild1.MyKey ;
       AND MyChild1.MyField = "MyVal" ;
    INNER JOIN MyChild2 ;
     ON MyParent.MyKey = MyChild2.MyKey ;
       AND MyChild2.MyField = "MyVal" ;
    INNER JOIN MyChild3 ;
      ON MyParent.MyKey = MyChild3.MyKey ;
       AND MyChild3.MyField = "MyVal" 
    WHERE MyParent.MyField1 = "MyVal" ;
    into cursror curTest 
HTH

Sorry for typo in the first message.
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform