Subject JOIN the mess
Author Scott Taylor
Hello all,

I just a little lost trying to get, what I thought was going to be a simple
join, to work.

Here is the case:
I have three tables, one with many records and fields disp_leg and two
master tables, Truck_ID and Trk_Hauls.

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

This works, but returns useless data, as soon as I add 'group by' or
'count' or both, ie:

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

I get this error:

ISC ERROR CODE:335544569

ISC ERROR MESSAGE:
Dynamic SQL Error
SQL error code = -104
invalid column reference

STATEMENT:
TIB_Cursor: "frmWISQL.crEdit"

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?