SQl maximum occurance of a object

  • Hi All,

    I'm new to SQL server.

    I have a table with two columns. 'Name' and 'Used food' . I want to find maximum used food for each name .

    Can someone help me.

    rgds,

    Amith

  • SELECT Name, MAX([Used Food]) AS Max_Used_Food

    FROM SomeTable

    GROUP BY Name

    -- Gianluca Sartori

  • Thanks for the quick reply. if I WANT THE NUMBER OF OCCURANCES AS WELL WHAT I SHOULD DO

  • SELECT Name, MAX([Used Food]),COUNT(Name) AS Max_Used_Food

    FROM SomeTable

    GROUP BY Name

    Try this...

  • SELECT Name, MAX([Used Food]) AS Max_Used_Food

    ,COUNT(Name) AS Count_Food

    FROM SomeTable

    GROUP BY Name

    I was little fast for the column header...try this.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply