Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2009

    Unanswered: How to count number of each unique values in a table?

    Hi all,

    I've searched on the net for a solution, but to no avail - I'm hoping for luck here

    Imagine this is the table:

    Prod_ID Quantity Sold
    ABCDEF 2
    123456 6
    ZZZZZZ 1
    ABCDEF 7
    ABCDEF 8
    ZZZZZZ 2

    So we have multiple entries of the same product with different quantities sold.

    I need to summarize the total quantity sold of each product i.e. the result would be:

    Prod_ID Quantity Sold
    ABCDEF 17
    123456 6
    ZZZZZZ 3

    Is this possible from a MySQL query, or would I need to use php scripting too?

    I've tried to think of how to do this using DISTINCT, GROUP BY, SUM etc but can't seem to be able to do it.


  2. #2
    Join Date
    Apr 2002
    Toronto, Canada
    this is fairly basic SQL
    SELECT Prod_ID
         , SUM(Quantity_Sold) AS total_qty
      FROM daTable
        BY Prod_ID | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts