----- Original Message ----- From: "Claire Lee" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, August 03, 2004 11:28 AM Subject: distinct based on two fields--please help
> I have a table like this > > name price type > A 10 1 > B 30 2 > A 20 1 > B 20 2 > > would like to distinct based on name and type, do a > sum and get the following result > > name price type > A 30 1 > B 50 2 > > How do I do this with one sql query? Thanks. > You don't need (or want) distinct in this case. select name, type, sum(price) from mytable group by name, type This will lump together all rows that have the same name/type combination and then sum the prices of those rows. The result will be exactly what you requested: a single row for each name/type combination showing the total for that combination. Rhino -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]