need an sql query for the following situation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shiniskumar
    New Member
    • Feb 2007
    • 58

    need an sql query for the following situation

    i need a query to get a collection ...
    Following is the situation.
    ive got a collection in which item of each element is different.
    but each element has an item_id tat can be same.all these elements have weightage... i need to get elements with unique item_id and max weightage.
    ie;
    i got a collection of elements such as

    e1 with item_id as 1 and weightage 7
    e2 with item_id as 2 and weightage 10
    e3 with item_id as 1 and weightage 8
    e4 with item_id as 5 and weightage 10
    e5 with item_id as 6 and weightage 10
    e6 with item_id as 1 and weightage 6
    so my result collection should contain the elements
    e3 with item_id as 1 and weightage 8
    e2 with item_id as 2 and weightage 10
    e4 with item_id as 5 and weightage 10
    e5 with item_id as 6 and weightage 10


    can i get this in a single sql query? please help
  • michaelb
    Recognized Expert Contributor
    • Nov 2006
    • 534

    #2
    Try this query
    [CODE=sql]
    SELECT item_id, max(weightage) FROM tabName group by item_id
    [/CODE]

    Comment

    Working...