I have situation where I have 3 tables in my query. I'm joining table 1 and 2 and selecting the max date in table 2. So far so good. But now I need to join the 3rd table on a column found in table 2.
Ex. table1
id
1
2
3
table2
id date empid
1 1/1/2005 123
1 2/1/2005 123
1 3/1/2005 456
table3
empid empname
123 Daffy
456 Duck
My sql:
SELECT Table1.id, Max(Table2.date) AS MaxOfdate, Table3.empname
FROM (Table1 INNER JOIN Table2 ON Table1.id = Table2.id) INNER JOIN Table3 ON Table2.empid = Table3.empid
GROUP BY Table1.id, Table3.empname;
I keep getting 2 rows back instead of just the one I'm expecing.
id MaxOfdate empname
1 2/1/2005 daffy
1 3/1/3005 duck
Ex. table1
id
1
2
3
table2
id date empid
1 1/1/2005 123
1 2/1/2005 123
1 3/1/2005 456
table3
empid empname
123 Daffy
456 Duck
My sql:
SELECT Table1.id, Max(Table2.date) AS MaxOfdate, Table3.empname
FROM (Table1 INNER JOIN Table2 ON Table1.id = Table2.id) INNER JOIN Table3 ON Table2.empid = Table3.empid
GROUP BY Table1.id, Table3.empname;
I keep getting 2 rows back instead of just the one I'm expecing.
id MaxOfdate empname
1 2/1/2005 daffy
1 3/1/3005 duck