mysql> select * from comments;
+-------+--------+
| idkto | idkomu |
+-------+--------+
| 1 | 2 |
| 1 | 3 |
| 1 | 4 |
| 1 | 5 |
| 2 | 3 |
| 2 | 6 |
| 3 | 1 |
| 4 | 2 |
+-------+--------+
8 rows in set (0.02 sec)
mysql> create temporary table tt as
-> select idkto,count(*) cn from comments group by 1
-> union
-> select idkomu,count(*) from comments group by 1
-> ;
Query OK, 8 rows affected (0.03 sec)
Records: 8 Duplicates: 0 Warnings: 0
mysql> select idkto,sum(cn) from tt group by 1 order by 2 desc;
+-------+---------+
| idkto | sum(cn) |
+-------+---------+
| 1 | 5 |
| 3 | 3 |
| 2 | 2 |
| 4 | 1 |
| 5 | 1 |
| 6 | 1 |
+-------+---------+
6 rows in set (0.00 sec)
mysql>