I have a table A that I need to join to table B. Table B holds important info including CreatedDate. I want to only return results for the most recent created date. My SQL below appears correct but it is returning multiple results since column Y has multiple distinct values for each row.
(X = Foreign Key, Y = Attribute that changes with each row)
SELECT *
FROM TABLE_A T
INNER JOIN
(SELECT X, Y, MAX(CreatedDate) AS Created
FROM TABLE_B
GROUP BY X, Y) SUB ON SUB.X = T.X
How do I prevent duplicated rows and only show the max created date row?
Thanks!