$strSQL = "SELECT * FROM tblname ORDER BY date DESC";
จาก code ตัวอย่างจะได้ข้อมูลว่า
custid name insert date
6 f 11 2012-02-12
5 e 10 2012-02-11
4 d 9 2012-02-11
3 c 8 2012-02-11
2 b 7 2012-02-11
1 a 6 2012-02-11
5 e 5 2012-02-10
4 d 4 2012-02-10
3 c 3 2012-02-10
2 b 2 2012-02-10
1 a 1 2012-02-10
แล้วพอ group by จะเป็น
$strSQL = "SELECT * FROM tblname GROUP BY cutid ORDER BY date DESC";
custid name insert date
6 f 11 2012-02-12
5 e 5 2012-02-10
4 d 4 2012-02-10
3 c 3 2012-02-10
2 b 2 2012-02-10
1 a 1 2012-02-10
INSERT INTO `customer` VALUES (1, 'poh', '2012-01-25');
INSERT INTO `customer` VALUES (1, 'poh', '2012-02-11');
INSERT INTO `customer` VALUES (3, 'Yo', '2012-01-21');
INSERT INTO `customer` VALUES (1, 'poh', '2012-02-05');
INSERT INTO `customer` VALUES (2, 'aoh', '2012-01-15');
INSERT INTO `customer` VALUES (1, 'poh', '2012-01-31');
INSERT INTO `customer` VALUES (3, 'Yo', '2011-11-21');
INSERT INTO `customer` VALUES (2, 'aoh', '2012-01-01');
INSERT INTO `customer` VALUES (3, 'Yo', '2012-03-11');
ง่ายๆไม่ยากครับ
SELECT `custid` as refid ,`name`,`datesale` FROM `customer` as t1
where datesale = (select max(datesale) from customer where custid=refid)
order by `name`