sample as below with group by and order by statment
mysql> create table t2(name char(1),qty smallint); Query OK, 0 rows affected (0.01 sec) mysql> insert into t2 values('A',1),('B',2),('A',4),('A',1),('A',1),('B',1),('A',2),('C',2),('D',1),('C',4); Query OK, 10 rows affected (0.00 sec) Records: 10 Duplicates: 0 Warnings: 0 mysql> select * from t2; +------+------+ | name | qty | +------+------+ | A | 1 | | B | 2 | | A | 4 | | A | 1 | | A | 1 | | B | 1 | | A | 2 | | C | 2 | | D | 1 | | C | 4 | +------+------+ 10 rows in set (0.00 sec) mysql> select name,sum(qty) as qty from t2 group by name order by qty desc; +------+------+ | name | qty | +------+------+ | A | 9 | | C | 6 | | B | 3 | | D | 1 | +------+------+ 4 rows in set (0.01 sec) Best Regards! Yang Wang ----- Original Message ----- From: "HaidarPesebe" <haidarpes...@gmail.com> To: "MySQL Lists" <mysql@lists.mysql.com> Sent: Monday, December 21, 2009 3:31 PM Subject: Most data sort Dear All, I need your help to how to call the database. I've got a mysql database as follows: ------------------ Name | qty ----------------- A 1 B 2 A 4 A 1 B 1 A 2 C 2 D 1 C 4 How calling if I want to sort the data according to the most, or the result will look like this A = 7 C = 6 B = 3 D = 1 Thanks a lot Haidarpesebe