Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to query 2 table that include all record in parent t
Message
 
À
13/12/1999 02:22:16
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00302598
Message ID:
00302623
Vues:
27
Dury,
You need a left outer join to get what you want. I don't recall if the outer join was introduced in VFP 3 or in 5 so I wil show you two ways to get this. If the first doesn't work use the second.
SELECT Item.Item_Code,Item.name,COUNT(order_Detail.ItemCode) ;
       FROM Inventory!Item LEFT OUTER JOIN Inventory!Order_Detail ;
         ON Item.Item_code = Order_detail.Item_code ;
      GROUP BY 2 ;
       INTO CURSOR MyResult
You need a GROUP BY or else the COUNT() field will be a bunch of 1's. Also you don't need SYS(2015) for the cursor name, cursors all purely local to the machine running the query and you can use meaningful names for them.

The alternative if the above does not work for you in 3.0;
SELECT Item.Item_Code,Item.name,COUNT(order_Detail.ItemCode) ;
       FROM Inventory!Item, Inventory!Order_Detail ;
      WHERE Item.Item_code = Order_detail.Item_code ;
 UNION ALL ;
SELECT Item.Item_Code,Item.name,0;
       FROM Inventory!Item ;
      WHERE Item.Item_code NOT IN(SELECT Item_code FROM Order_detail) ;
      GROUP BY 2 ;
       INTO CURSOR MyResult
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform