How to select for duplicate product in woocomerce using sql
<p>I am using woocomerce platform and I have duplicate entries of product name. Now, I want to see the categories_id,categories_name, products_name of duplicate "product_name" entered by the user group by a specific category name. </p>

<p>As I see on the database tables, here are the needed tables to view for the result:</p>

<p>Based on the table schema below:</p>

<pre><code>  --------------------------
  | categories_description |
  --------------------------
   categories_id(PK)
   categories_name

  -----------------------
  | products_description |
  -----------------------
  products_id
  products_name


  ----------------------
  |products_to_categories |
  ----------------------- 
   products_id
   categories_id 
</code></pre>

<p>My query:</p>

<pre><code>  SELECT  prod.products_id, `products_name`, categories_name,      
  prodcat.categories_id , count(*) c
  FROM
   (products_description AS prod INNER JOIN  products_to_categories AS               
    prodcat ON prod.products_id=prodcat.products_id)
    INNER JOIN 
    categories_description AS catdesc ON    
    catdesc.categories_id=prodcat.categories_id AND categories_name= 'CARD  
    HOLDERS'  
    GROUP BY products_name 
    order by categories_name
</code></pre>

<p>The problem with my query is that, <strong>it cannot display the list of entries duplicate product name</strong>.</p>

<pre><code>example Inputs:

 products_description 
 ---------------------------
 products_id  | products_name
      1            pens
      2            pens
      3            cars
      4            cars
      5            cars
      6            burgers

 products_to_categories
  -------------------------------
  products_id    |  categories_id
       1                 1
       2                 1
       3                 2
       4                 2
       5                 2
       6                 3     

  categories_description 
  ------------------------------
    categories_id | categories_name
        1                School Supply
        2                Vehicles
        3                 Foods

   =================================
   Expected Output
   =================================
   products_name  categories_name    categories_id     total_count
      pens          School Supply         1             2
      cars           Vehicles             2             3
      burgers           Foods             3             1
</code></pre>

<p>take a look at total count. It depends on number of occurrence in products_description table</p>

<p>Please help.</p>