Simple query problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Boefje

    #1

    Simple query problem

    What I want is fairly simpel, but I can't figure it out.

    Problem: Select the article (the articles) with the highest price for
    each article group.

    table articles
    ---------------

    id=1, description='ar ticle1', price=100, articlegroupid= 4
    id=2, description='ar ticle2', price=200, articlegroupid= 5
    id=3, description='ar ticle3', price=900, articlegroupid= 5
    id=4, description='ar ticle4', price=900, articlegroupid= 5
    id=5, description='ar ticle5', price=200, articlegroupid= 4
    id=6, description='ar ticle6', price=100, articlegroupid= 6
    id=7, description='ar ticle7', price=300, articlegroupid= 6
    id=8, description='ar ticle8', price=500, articlegroupid= 6
    id=9, description='ar ticle9', price=400, articlegroupid= 6

    expected result
    -------------------
    id=5, description='ar ticle5', price=200, articlegroupid= 4
    id=3, description='ar ticle3', price=900, articlegroupid= 5
    id=4, description='ar ticle4', price=900, articlegroupid= 5
    id=8, description='ar ticle8', price=500, articlegroupid= 6


    What I have got is the following (but it doesn't do the trick):

    SELECT
    artikelen.id,
    artikelen.omsch rijving,
    MAX(artikelen.p rijs),
    artikelen.artik elgroep
    FROM
    artikelen
    GROUP BY
    artikelgroepid
    ORDER BY
    artikelgroepid

    Can you help me out? Thanx
  • Felix Geerinckx

    #2
    Re: Simple query problem

    On 20/04/2005, Boefje wrote:
    [color=blue]
    > What I want is fairly simpel, but I can't figure it out.
    >
    > Problem: Select the article (the articles) with the highest price for
    > each article group.[/color]

    See
    http://dev.mysql.com/doc/mysql/en/ex...group-row.html


    --
    felix

    Comment

    Working...