GROUP BY and ORDER BY in same MySQL query? -
i want select bunch of data table using group by clause. works great, need order data date created, order by clause. question is, can use both these clauses within same query, or should using 1 in sub-query, or else?
the original query (no modification) this:
select * table tag_draft=0 , ( (target_id=2 , tag_del_target=0) or (source_id=2 , tag_del_source=0) ) , updated in ( select max(updated) table group thread_id ) order updated desc hopefully question readable enough able answer it.
the mysql select syntax is:
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 {col_name | expr | position} [asc | desc], ... [with rollup]] [having where_condition] [order {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 | dumpfile 'file_name' | var_name [, var_name]] [for update | lock in share mode]] so yes, can use group , order in same query. won't order results use order in sub-query. example:
select atable join (select myid anothertable order myid) btable on atable.id=btable.myid it doesn't make sense first order sub-query, make join.
Comments
Post a Comment