How to get the last occurrence of a field

Discussion in 'General MSSQL Discussion' started by tim8w, Feb 23, 2021.

  1. tim8w

    tim8w

    Joined:
    Feb 23, 2021
    Messages:
    1
    Likes Received:
    0
    Hi,

    I have a simple query that returns two fields. I need to modify that query so that it only returns the last or highest number for each pair of fields.

    It's easier to show than explain. Here's my query:

    SELECT WONum, OpNum
    FROM tblHistory
    ORDER BY WONum, OpNum

    It returns something like this:

    WONum OpNum
    1396026 40.00
    1396026 90.00
    1396026 90.00
    1396026 120.00
    1427600 130.00
    1456392 120.00
    1456392 130.00
    1458018 230.00
    1458018 280.00
    1460224 40.00
    1460224 80.00

    I need it to return:
    WONum OpNum
    1396026 120.00
    1427600 130.00
    1456392 130.00
    1458018 280.00
    1460224 80.00

    Just the last row of each WONum, OpNum pair
     
    tim8w, Feb 23, 2021
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.