select date, pid, a from (select * from aaa where date <= '2011-11-11' order by date desc) as s group by pid; +------------+------+------+ | date | pid | a | +------------+------+------+ | 2011-11-10 | 7 | 59 | | 2010-10-10 | 8 | 5 | | 2010-10-10 | 9 | 5 | +------------+------+------+ 3 rows in set (0.00 sec)