MYsql 3 table query help

Discussion in 'MySQL' started by MASsIVE, Feb 14, 2007.

  1. #1
    Hi all

    I have 3 tables im pretty sure I need data from to achieve a top ten selling items in a certain category if possible I would greatly appreciate some assistance, comments and or solution.

    Heres the table structures
    product [table]
    *************
    productID
    name
    catID
    price
    approved

    Which is related to:
    sold [table]
    ******
    productID
    total [total sold]

    and
    category [table]
    ******
    catID
    catDesc
    parentID

    What Im attempting is to get the Top Ten products sold from a certain category then duplicating the file and simply change the catID in the query to get multiple blocks on my site to display Top Ten for several categories.

    Any help would be greatly appreciated.

    Thanks
    regards
    MASsIVE
     
    MASsIVE, Feb 14, 2007 IP
  2. ThomasNederman

    ThomasNederman Peon

    Messages:
    112
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    it would be something like this
    select sum(total),name,p.productID from product p inner join sold s on p.productID= s.productID group by p.productID order by sum(total) desc limit 10;

    Good luck
     
    ThomasNederman, Feb 15, 2007 IP