• @Gazareth

    Yes it's MAX, this is a aux table with some comments to every pf at another table.

    At this point i need to return every row, it's kind of report with every comment that the user added for each pf in the master table.

    The join it's a simple Left Join:

    LEFT OUTER JOIN (SELECT ROW_NUMBER() OVER (PARTITION BY pf ORDER BY Data DESC, idAuxiliarPF DESC) AS RN,

    pf ,

    Data ,

    Descr

    FROM dbo.PFAuxiliar

    WHERE Data <= GETDATE()) PFAE

    ON PFAE.pf = PF.idPF

    @scottpletcher

    I didnt use the pf as key, because it's not unique, i can have several comments for each pf...

    Only another thing, if i run the query without the ROW_NUMBER and OVER PARTITION, the query doesn't take 1 second to run.

    SELECT pf ,

    Data ,

    Descr

    FROM dbo.PFAuxiliar

    WHERE Data <= GETDATE()

    Thanks for your time.