Query Help

  • I'm stuck here.

    I've been trying to find a way to select the latest FinancialYear record for each member from this table (i.e. the highlighted records).

    Is it even possible to grab the wanted records in a single query?

  • If you aren't dealing with a large amount of data something like this should work.

    SELECT * FROM tableName a

    WHERE financialYear = (SELECT MAX(financialYear) FROM tableName b

    WHERE a.memberID = b.memberID)

  • Why not this:

    select

    MemberID,

    max(FinancialYear) as FinancialYear

    from

    dbo.MyTable

    group by

    MemberID;

  • Yeah, I was assuming the whole row was needed. Probably should have asked what the expected outcome was.

  • Thanks Matt & Lynn.

    Sorry for not being clear enough. I did want the entire row returned, so I ended up using Matt's script.

    Thank you both again for your help 🙂

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply