Sort within GROUP BY
CREATE TABLE `oper` (
`id_num` int(10) unsigned NOT NULL auto_increment,
`id_country` int(10) unsigned NOT NULL,
`cost` decimal(4,2) unsigned NOT NULL default '0.00',
PRIMARY KEY (`id_num`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
id_num id_country cost
1 1 1
2 1 2
3 1 3
4 1 4
5 2 5
6 2 6
7 2 7
8 2 8
it is necessary to choose the most expensive rooms on the countries and their ID
select id_num, id_country, max(cost) from oper group by id_country
gives just such a thing
id_num id_country max(cost)
1 1 4
5 2 8
ie prices pick correct, but the ID numbers did not match the price tag, should be so
id_num id_country max(cost)
4 1 4
8 2 8