Query returns WRONG FIELD!!!

So here's yet another wrinkle. This query is fine:

SELECT ByPN_1.PartNumber, ByPN_1.LostPerSetup
FROM (ByPN_1 LEFT JOIN FeederCost1 ON (ByPN_1.ActualMachine = FeederCost1.Machine) AND (ByPN_1.FirstOfFeederSize = FeederCost1.Size) AND (ByPN_1.FirstOfType = FeederCost1.Type)) LEFT JOIN master_attr ON ByPN_1.PartNumber = master_attr.ITEM;
It returns:
PartNumber LostPerSetup
103330 2
103405 2
105921 1
105939 2
105954 4
105965 4
But if I do nothing more than add the "lostpersetup" field a 2nd time (regardless of whether I then try to perform any calculations on it)
SELECT ByPN_1.PartNumber, ByPN_1.LostPerSetup, ByPN_1.LostPerSetup
FROM (ByPN_1 LEFT JOIN FeederCost1 ON (ByPN_1.ActualMachine = FeederCost1.Machine) AND (ByPN_1.FirstOfFeederSize = FeederCost1.Size) AND (ByPN_1.FirstOfType = FeederCost1.Type)) LEFT JOIN master_attr ON ByPN_1.PartNumber = master_attr.ITEM;

I'm back to:
PartNumber Expr1001 LostPerSetup
103330 16X 16X
103405 16X 16X
105921 24X 24X
105939 16X 16X
105954 8X4 8X4
105965 8X4 8X4

Surely it's not a no-no to use the same field twice in one query????? I know I've done this many, many times in other queries.
 
OK, I may be getting closer to the source of the problem. Since the "lostpersetup" field seems key, I went back to look at the ByPN_1 query. I changed the lostpersetup field from
First((nz([QtyLostPerSetup],0))) AS LostPerSetup
to a "group by" instead. That makes the problem go away.

I sometimes use "first" as a shortcut when I'm dealing with dirty data, to filter out duplicates. HOwever, I don't really need it here as duplicates will be prevented by the primary key in table PartLossPerSetup.
 

Users who are viewing this thread

Back
Top Bottom