Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting rid of SQL Select duplicates
Message
From
19/08/1999 14:58:44
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
19/08/1999 14:35:31
Rex Mahel
Realm Software, Llc
Ohio, United States
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00255446
Message ID:
00255459
Views:
11
>All,
>
>I am writing a building inspection application.
>
>Each DISTICT has one or more BUILDINGS
>Each BUILDING has one or more ADDITIONS
>Each ADDITION has one or more INSPECTIONS
>Each INSPECTION has one or more INSPECTIONCOMPONENT
>Each INSPECTIONCOMPONENT has one or more INSPECTIONCOMPONENTITEM
>Each ITEM has one or more INSPECTIONCOMPONENTITEM
>
>I need to sum the extension of the INSPECTIONCOMPONENTITEM quantity and the ITEM unit cost for a specific building using the following:
>
>SELECT ;
> SUM(SFAInspectionComponentItem.iQuantity * SFAItem.yUnitCost) AS iTotal;
>FROM ;
> sfa!sfainspectioncomponent ;
> INNER JOIN sfa!sfainspectioncomponentitem;
> INNER JOIN sfa!sfaitem;
> INNER JOIN sfa!sfainspectioncomponent;
> INNER JOIN sfa!sfaaddition;
> INNER JOIN sfa!sfabuilding ;
> ON Sfabuilding.iid = Sfaaddition.ibldgid ;
> ON Sfaaddition.iid = Sfainspection.iadditionid ;
> ON Sfainspection.iid = Sfainspectioncomponent.iinspectionid ;
> ON Sfainspectioncomponent.iid = Sfainspectioncomponentitem.iinspectioncomponentid;
> ON Sfaitem.iid = Sfainspectioncomponentitem.icomponentitemid ;
>WHERE Sfabuilding.iid = ?vp_iBuildingId ;
>INTO CURSOR REX
>
>Unfortunately the total is double what it should be. In my example there are 2 COMPONENTS for the INSPECTION and this seems to lead to a complete duplication of all the amounts.
>
>Since I am using a SUM, I cannot use DISTINCT is the SQL.
>
>How can I get the data not to duplicate?
>
>TIA
>
>Rex
Rex,
Isn't there a typo in code ? Second "ON" seems to be causing the problem.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform