Write a sql statement in SQL2000 to pull the lowest priced items

Posted on 2009-02-10
Last Modified: 2012-05-06
I need to pull items/records that have the lowest price from a table with multiple distributors based on these three fields, "price" of course, and then "mfgID" and "UPC".  The table has many fields that I will keep for that record with the lowest price.  Some items may only have one occurrence in the table while others may have many so for those with just one occurrence I would keep but for the repeated entires I would keep only the lowest price.

Thanks in advance for your help
Question by:BlueKnight66
    LVL 35

    Expert Comment

    do you mean the lowest price in the table or something liek 5 or 10 lowest prices?
    LVL 35

    Expert Comment

    SELECT * FROM Table1 WHERE price = (SELECT MIN(price) FROM Table1)

    Author Comment

    Thanks for the reply BUT that won't help me because there are multiple products in the table.  Your selct staement would only return the product with the lowest price regardless of the item number.  I need that type of query BUT with a grouping by UPC+mfgID
    LVL 40

    Accepted Solution


    check this one. If you still have issues, then provide the table structure or sample data with expected result.
    SELECT t1.*
      FROM YourTable t1
        ON t1.MfgID = t2.MfgID AND t1.UPC = t2.UPC AND t1.Price = t2.Price

    Open in new window


    Author Closing Comment

    Thank you Sharath 123 and to all those that contributed
    LVL 40

    Expert Comment

    most welcome.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
    Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now