Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1106145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:44:47+00:00 2026-05-17T01:44:47+00:00

I want to select a bunch of data from a table using a GROUP

  • 0

I want to select a bunch of data from a table using a GROUP BY clause. This works great, but I need to order the data by the date it was created, with an ORDER BY clause. My question is, can I use both these clauses within the same query, or should I be using one in a sub-query, or something else?

The original query (no modification) is this:

SELECT * 
FROM table 
WHERE tag_draft=0 
AND 
(
    (target_id=2 AND tag_del_target=0) 
    OR (source_id=2 AND tag_del_source=0)
) 
AND updated IN
(
    SELECT MAX(updated) 
    FROM table 
    GROUP BY thread_id
) 
ORDER BY updated DESC

Hopefully this question is readable enough to be able to answer it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T01:44:48+00:00Added an answer on May 17, 2026 at 1:44 am

    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 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 won’t order the results properly is to use ORDER BY in a sub-query. For example:

    SELECT 
           something
    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bunch of anchor tags that I want to select. But if
i have users table and i have posts table i want select from users
i have this lists, and i want select li element from jquery when the
I want to select one record at a time from a MySQL table. I
I want to know if it's possible to select incremented integer from mysql table?
I have a bunch of timestamped rows (using the 'datetime' data type) I want
I need help to do range select on jqgrid data using the filter toolbar
I want to select distinct or unique records from a database I am querying.
This query works: SELECT Article.id, Article.post_time, Article.post_locked, Article.comments_locked, Article.title, IF(CHAR_LENGTH(Article.content)>2000, RPAD(LEFT(Article.content,2000),2003,'.'), Article.content) as content,
So I have this SQL table that I need to update. Now we use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.