I have two tables (A & B).
I want all data from Table A. Table B has notes that reference the PKs from Table A via foreign key. I want to bring back all data from Table A and the most recent note ONLY from table B (there is a DateTime column in table B). I need all data from table A regardless if there is a note in Table B or not.
Thank you for any help.
>Solution :
SELECT
A.*,
B.Note
FROM
A
LEFT JOIN (
SELECT
fk,
Note,
ROW_NUMBER() OVER (PARTITION BY fk ORDER BY InsertDate DESC) AS rn
FROM
B
) B ON B.fk = A.pk AND B.rn = 1;