Subject Re: [ib-support] JOIN the mess
Author Lucas Franzen
Scott,


> select d.trkid, t.LeaseOpID
> from disp_leg d
> join Truck_ID t on d.TrkID = t.TrkID
> group by d.trkid

in general:
Every column you have in select clause taht is NOT a statistic function
(SUM, COUNT, etc.) MUST have a corresponding entry in the group by
clause.

This is not an IB/FB restriction, this is just SQL syntax.
Change it to:

select d.trkid, t.LeaseOpID
from disp_leg d
join Truck_ID t on d.TrkID = t.TrkID
group by d.trkid, t.LeaseOpID

and it will work - but only give you an overview of all combinations of
this two fields.


> Ultimately, this statement works well:
> SELECT COUNT (*) numhauls, d.TrkID
> , SUM(h.cycletime) CycleTime
> FROM disp_leg d
> JOIN Truck_ID t on d.TrkID = t.TrkID
> JOIN Trk_Hauls h on d.HaulID = h.HaulID
> WHERE d.dumpdate >= '03/01/03'
> AND d.dumpdate <= '03/03/03'
> AND d.complete = 'Y'
> AND d.TrkID >= '1'
> AND d.TrkID <= '20'
> GROUP BY d.TrkID
>
> This gives me everything I need, except the t.leaseopid, when I add it to
> the list I get back to that error message again.
>
> Only slightly frustrating. Can anyone point out my obvious mistake?

see above.
Add "t.leaseopid" to yor SELECT __AND__ your GROUP BY.


Luc.