[PHP-DB] Get ID of ROW when using aggregate functions

2009-04-08 Thread Ondrej Kulaty
Hi, I have following table: id int(11) name varchar(255) company varchar(255) sallary int(11) CREATE TABLE `test` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `company` varchar(255) NOT NULL, `sallary` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM

Re: [PHP-DB] Get ID of ROW when using aggregate functions

2009-04-08 Thread Jack van Zanen
the answer is exactly what you asked for. It gave you the max salary per company and made a lucky guess (not really, alfabetically first) as to which name you wanted since you never specified this of the top of my head, try this. SELECT a.id,a.name,a.company,a.sallary FROM `test` a ,(select

Re: [PHP-DB] Get ID of ROW when using aggregate functions

2009-04-08 Thread kesavan trichy rengarajan
there is probably a better way to achieve this, but, this is a quick solution mysql SELECT * FROM test where sallary IN (SELECT MAX(SALLARY) FROM test GROUP BY company); +++---+-+ | id | name | company | sallary | +++---+-+ | 2 | Peter