Last two prices by Item No

Discussion in 'General MSSQL Discussion' started by Vipul, May 19, 2021.

  1. Vipul

    Vipul

    Joined:
    May 19, 2021
    Messages:
    1
    Likes Received:
    0
    How to extract last two prices by ItemNo

    I have two tables:

    OrderItems Table

    OrderId OrderDate ItemNo ItemDescrepation Unit Price
    1001 03-15-2020 91570 Charger 12V $50
    1205 05-06-2020 91570 Charger 12V $80
    3020 04-20-2021 91570 Charger 12V $100

    1050 04-18-2020 89002 Hard Drive 1GB $200
    2045 06-08-2020 89002 Hard Drive 1GB $180
    3350 05-03-2021 89002 Hard Drvie 1GB $200
    4590 05-18-2021 89002 Hard Drive 1GB $220


    Orders Table

    OrderId Supplier Buyer
    1001 BestBuy George
    1050 Microcenter George
    1205 BestBuy George
    3020 Microcenter George
    3350 BestBuy George
    4590 BestBuy George

    There are many orders in Orders table and many different items for each order.
    Same items may be repeated in different orders.

    I would like to get last(latest) two prices and item no by the Buyer for each item joining these two tables.
     
    Vipul, May 19, 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.