Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Another SQL Otimization if posible
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 8
OS:
Windows XP
Network:
Windows 2003 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01066992
Message ID:
01067001
Views:
21
The query will give incorrect result in cases when there're multiple records in both child tables for a product. To understand why, consider what result you'll get if you run it w/o SUM and GROUP BY for one such product.

>
>   ** Put all non agregated fields in GROUP BY to not have problems with SET ENGINEBEHAVIOUR
>   ** Don't use ALLTRIM()
>   SELECT products.prodid,;
>          product.name,;
>          product_price,;
>          SUM(NVL(bill_items.qty,0)) AS OQty,;
>          SUM(NVL(input_items.qty,0) AS IQty;
>     FROM products;
>     LEFT JOIN bill_items  ON product.prodid == bill_items.prodid;
>     LEFT JOIN input_items ON product.prodid == input_items.prodid;
>     GROUP BY products.prodid,product.name, product_price;
>     ORDER BY products.prodid ;
>INTO CURSOR output1
>
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform