Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8680559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:16:58+00:00 2026-06-12T21:16:58+00:00

I am working on a website using opencart and have it setup to automatically

  • 0

I am working on a website using opencart and have it setup to automatically import products from two different wholesalers. The database contains about 40,000 different products in it, and about 10,000 of them are duplicates (both carry the product).

I need to lookup all duplicate products (by UPC) and enable the product with the lower price.

The table is called “product” and has the columns product_id, upc, price, status, and others that aren’t relavent.

My first attempt was to run the following query

SELECT DISTINCT (
upc
) AS upcDuplicate, COUNT( upc ) AS upcCount
FROM product
GROUP BY upc
HAVING upcCount >1

which gave me a list of all duplicate products, then I was going to loop through those upcs in php and run

UPDATE product SET status=1 WHERE upc='CURRENTUPC' ORDER BY price ASC LIMIT 1

which would enable the one with the lowest price.

This works, but seems very inneficient seems how it is relying on php to run 10,000 different mysql queries. Is there any way to put this into a single query, or at least something more efficient.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T21:16:59+00:00Added an answer on June 12, 2026 at 9:16 pm

    Not tested, so it may kick your dog and steal your lunch money, but…

    UPDATE product
    INNER JOIN (
        SELECT upc, MIN(price) AS minprice
        FROM product
        GROUP BY upc
    ) AS derived_product
    SET product.status=1
    WHERE product.upc = derived_product.upc AND product.price=derived_product.minprice
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a website and have been using absolute positioning, since the viewport
Working on a website that has Employee and Branch entities, using a database table
I am working on a website using Smarty. I have searched the web to
I have been working on a website using MVC Preview 1 since it came
I'm working on a website using friendly URLs. We want to have www.website.com/johndoe go
I am working on Project where I have JQuery 1-Page Horizontal scrolling website using
I am working on a website using Google maps apiv3. I have a button
I have been working on a website using mod_python, python, and SQL Alchemy when
I'm working on a soccer league management website using Django. Among others, I have
I have built a test website using nopCommerce open source , Everything is working

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.