bubbisthedog
Programmer
Hello, all. First post. Following are my table structures ("*" indicates primary keys):
TA: EM_ID*, FNAME, LNAME (unique entries)
TB: EM_ID, DP_ID, SDATE (not unique entries)
TC: DP_ID*, DESC (unique entries)
As you can see, TB is my intermediate table, and can include non-unique EM_IDs and DP_IDs. I am seeking to retrieve records that contain
1) Unique EM_IDs (whereupon I can get unique first and last names) based on the most recent department that employees work in (MAX(TB.SDATE) would accomplish this);
2) The employees' departments corresponding to the record containing MAX(TB.SDATE).
RESULT:
FNAME | LNAME | DESC | MAX(SDATE)
I have not been able to accomplish this because GROUP BY requires that I use
That is, optimally, I'd like to have
which makes sense to me; but SQL does not allow it. I hope this all makes some sense. I'd greatly appreciate help getting the results that I'm seeking.
Thank you very much in advance,
bubbis
TA: EM_ID*, FNAME, LNAME (unique entries)
TB: EM_ID, DP_ID, SDATE (not unique entries)
TC: DP_ID*, DESC (unique entries)
As you can see, TB is my intermediate table, and can include non-unique EM_IDs and DP_IDs. I am seeking to retrieve records that contain
1) Unique EM_IDs (whereupon I can get unique first and last names) based on the most recent department that employees work in (MAX(TB.SDATE) would accomplish this);
2) The employees' departments corresponding to the record containing MAX(TB.SDATE).
RESULT:
FNAME | LNAME | DESC | MAX(SDATE)
I have not been able to accomplish this because GROUP BY requires that I use
Code:
SELECT TB.EM_ID, TB.DP_ID, MAX(TB.SDATE)
FROM TB
GROUP BY TB.EM_ID, TB.DP_ID
Code:
SELECT TB.EM_ID, TB.DP_ID, MAX(TB.SDATE)
FROM TB
GROUP BY TB.EM_ID
Thank you very much in advance,
bubbis