--source include/have_innodb.inc create table __test1 ( id int not null auto_increment, a int, b int, c int, primary key (id), key idx_a (a), key idx_b (b), key idx_c (c) ) #engine = innodb default character set = latin2; insert into __test1 (id,a,b,c) values (1,1,1,1),(2,1,1,2),(3,1,1,3); select (select id from __test1 t1 where t1.a=t.a and t1.b=1 order by t1.c desc limit 1) from (select 1 as a) as t;