root@natasha:test> CREATE TABLE t (grade_id INT UNSIGNED NOT NULL, grade_name CHAR(1) NOT NULL, price CHAR(3) NOT NULL, update_date DATE);
Query OK, 0 rows affected (0.10 sec)
root@natasha:test> INSERT INTO t VALUES (1, 'A', '8$', '2011-02-01'), (1, 'A', '10$', '2011-03-01'), (1, 'A', '20$', '2011-04-01'), (2, 'B', '10$', '2011-02-01'), (2, 'B', '20$', '2011-03-01'), (2, 'B', '30$', '2011-04-01');
Query OK, 6 rows affected (0.13 sec)
Records: 6 Duplicates: 0 Warnings: 0
root@natasha:test> SELECT * FROM t;
+----------+------------+-------+-------------+
| grade_id | grade_name | price | update_date |
+----------+------------+-------+-------------+
| 1 | A | 8$ | 2011-02-01 |
| 1 | A | 10$ | 2011-03-01 |
| 1 | A | 20$ | 2011-04-01 |
| 2 | B | 10$ | 2011-02-01 |
| 2 | B | 20$ | 2011-03-01 |
| 2 | B | 30$ | 2011-04-01 |
+----------+------------+-------+-------------+
6 rows in set (0.00 sec)
root@natasha:test> SELECT * FROM (SELECT * FROM t WHERE update_date < DATE(NOW()) ORDER BY update_date DESC) AS `t` GROUP BY grade_id;
+----------+------------+-------+-------------+
| grade_id | grade_name | price | update_date |
+----------+------------+-------+-------------+
| 1 | A | 10$ | 2011-03-01 |
| 2 | B | 20$ | 2011-03-01 |
+----------+------------+-------+-------------+
2 rows in set (0.00 sec)