加入声明......如何做ORDER BY?

时间:2010-11-18 01:25:56

标签: mysql

我有以下LEFT JOIN语句(尽管可能也适用于更简单的SELECT语句):

SELECT * FROM t1 LEFT JOIN t2 ON t2.c = t1.c WHERE t1.m LIKE 'captain%' GROUP BY     
t1.c ORDER BY t2.date DESC LIMIT 0,10

返回结果但是t2.date DESC没有对它们进行排序......我想这是因为那里有GROUP BY语句。如何对结果进行分组并对其进行排序?

THX

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

将查询放在子查询中,然后使用ORDER BY。

SELECT *
FROM
 (SELECT * 
  FROM t1 LEFT JOIN t2 ON t2.c = t1.c 
  WHERE t1.m LIKE 'captain%' 
  GROUP BY t1.c DESC LIMIT 0,10) l1
ORDER BY date