The MySQL SELECT commannd is like this:
SELECT
[ALL | DISTINCT | DISTINCTROW ]
[HIGH_PRIORITY]
[STRAIGHT_JOIN]
[SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT]
[SQL_CACHE | SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS]
select_expr [, select_expr ...]
[FROM table_references
[WHERE where_condition]
[GROUP BY {col_name | expr | position}
[ASC | DESC], ... [WITH ROLLUP]]
[HAVING where_condition]
[ORDER BY {col_name | expr | position}
[ASC | DESC], ...]
[LIMIT {[offset,] row_count | row_count OFFSET offset}]
[PROCEDURE procedure_name(argument_list)]
[INTO OUTFILE 'file_name' export_options
| INTO DUMPFILE 'file_name'
| INTO var_name [, var_name]]
[FOR UPDATE | LOCK IN SHARE MODE]]
so YES, you can use GROUP BY and ORDER BY in the same query.
What you cannot use is ORDER BY in a sub-query. For example this:
SELECT
somethig
FROM
aTable
JOIN
(SELECT myID FROM anotherTable ORDER BY myID) as bTable
ON aTable.ID=bTable.myID
It doesn't make any sense first to order the sub-query, then to make join.
Parkyprg
2010-09-29 17:11:35