I have two tables, say A and B.
Table : A
ID_Sender | Date
________________________
1 | 11-13-2013
1 | 11-12-2013
2 | 11-12-2013
2 | 11-11-2013
3 | 11-13-2013
4 | 11-11-2013
Table : B
ID | Tags
_______________________
1 | Company A
2 | Company A
3 | Company C
4 | Company D
result table:
Tags | Date
____________________________
Company A | 11-13-2013
Company C | 11-13-2013
Company D | 11-11-2013
I have already tried out this out GROUP BY with MAX(DATE) but failed with no luck, I did some inner joins and subqueries but failed to produce the output.
Here is my code so far, and an image for the output attached.
SELECT E.Tags, D.[Date] FROM
(SELECT A.ID_Sender AS Sendah, MAX(A.[Date]) AS Datee
FROM tblA A
LEFT JOIN tblB B ON A.ID_Sender = B.ID
GROUP BY A.ID_Sender) C
INNER JOIN tblA D ON D.ID_Sender = C.Sendah AND D.[Date] = C.Datee
INNER JOIN tblB E ON E.ID = D.ID_Sender
Any suggestions? I'm already pulling my hairs out ! (maybe you guys can just give me some sql concepts that can be helpful, the answer is not that necessary cos I really really wanted to solve it on my own :) )
Thanks!