What I have is 2 tables. table A looks like:
actID; jobnumber; actTypeID; completeDate
1; 2000; 3; 2012-09-04
2; 2000; 4; 2012-09-05
3; 2001; 2; 2012-09-10
4; 2001; 4; 2012-09-05
5; 2001; 5; 2012-09-05
6; 2002; 1; 2012-09-12
Table B looks like:
actTypeID; actType; projStatus;
1; Pick; Build;
2; Bid; Estimate;
3; PMQC; QC;
4; Equipment Test; QC;
5; Assembly; Build;
What I need to do is include the projStatus and actType in this:
SELECT jobnumber,
max(completedate) completedate
FROM tableA
GROUP BY jobnumber
without increasing the number of records returned, ie get this set back:
jobnumber; actType; projStatus; completedate;
2000; EquipmentTest; QC; 2012-09-05;
2001; Bid; Estimate; 2012-09-10;
2002; Pick; Build; 2012-09-12;
I’m on SQL server 2005 right now, soon to be 2008. I feel like I’m missing the trick to this.
Try this,
SQLFiddle Demo