----- Original Message ----- From: "Luis Lebron" <[EMAIL PROTECTED]> > Select M.Catid, sum(M.Hours) as allotedhours, sum(T.Hours) as usedHours > >From Manhours as M, Tasks as T > Where M.ProjectId=32 > AND T.ChargeNum=M.ChargeNum > AND T.EmployeeID=M.EmployeeID > AND T.Catid=M.Catid > Group by M.Catid > Order by M.Catid
It might be more understandable if you read it like: SELECT M.Catid, SUM(M.Hours) AS allotedhours, SUM(T.Hours) AS usedHours FROM Manhours AS M INNER JOIN Tasks as T USING (ChargeNum, EmployeeID, Catid) WHERE M.ProjectId=32 GROUP BY M.Catid Is it correct that the two tables are joined on three columns? Maybe it's best to try and refrase how the data in the two tables is connected and what exactly you want to retrieve. Try to think in data: "for project 32 I want all the records from table a plus the records from table b which have the same value for col_name, sum the values in col_name and sort them by col_name". From this you will be able to construct your query easily... Regards, Jigal. -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]