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

  • Home
  • SEARCH
  • 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 3346658
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:19:48+00:00 2026-05-18T01:19:48+00:00

I don’t have very much experience with MySQL so I am not sure what

  • 0

I don’t have very much experience with MySQL so I am not sure what information I should include when asking this question. If I am missing something relevant leave a comment. I will promptly add it.

I have this query:

SELECT 
        Log_Analysis_RecordsToSesions_dalhousie.sessionID, 
        (TIMEDIFF(
                MAX(Log_Analysis_Records_dalhousie.date), 
                MIN(Log_Analysis_Records_dalhousie.date) 
        )) as NewSessionLength
FROM 
        Log_Analysis_RecordsToSesions_dalhousie, 
        Log_Analysis_Records_dalhousie
WHERE
        Log_Analysis_RecordsToSesions_dalhousie.recordID=Log_Analysis_Records_dalhousie.recordID
GROUP BY
        sessionID;

Which returns this:

+-----------+---------------+
| sessionID | SessionLength |
+-----------+---------------+
|         1 | 00:20:31      | 
|         2 | 00:19:54      | 
|         3 | 00:04:01      | 
|         4 | 00:14:02      | 
|         5 | 00:02:16      | 
|         6 | 00:16:25      | 
|         7 | 00:00:00      | 
|         8 | 00:00:00      | 
|         9 | 00:00:00      | 
|        10 | 00:26:35      | 
|        11 | 00:11:28      | 
|        12 | 00:00:00      | 
|        13 | 00:00:00      | 
|        14 | 00:11:03      | 
  ...
|      7978 | 00:00:03      | 
|      7979 | 00:00:15      | 
|      7980 | 00:00:00      | 
|      7981 | 00:00:00      | 
+-----------+---------------+
7981 rows in set (0.92 sec)

When I append

ORDER BY
        NewSessionLength;

To the query it mostly sorts it but does not get it 100% correct. Most of the big values get put at the end of the table and most of the small values get put at the beginning. I have no idea what is causing this.

For example:

+-----------+------------------+
| sessionID | NewSessionLength |
+-----------+------------------+
|      4285 | 00:00:00         | 
|      1565 | 00:00:00         | 
|      7604 | 00:00:02         | 
|      4317 | 00:00:02         | 
|      1597 | 00:00:02         | 
|      7636 | 00:00:01         | 
|      4349 | 00:18:17         | // <-------------- Out of order
|      1629 | 00:00:09         | 
  ...
|      2829 | 04:28:01         | 
|       377 | 04:25:23         | // <-------------- Out of the order
|      5631 | 05:37:25         | 
|        18 | 05:05:31         | 
|      1545 | 07:01:31         | 
|      7536 | 07:09:59         | 
|      5237 | 10:07:29         | 
|       250 | 90:42:30         | 
+-----------+------------------+
7981 rows in set (0.94 sec)
  • 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-18T01:19:49+00:00Added an answer on May 18, 2026 at 1:19 am

    In MySQL version 5.0.50 there was a bug (#32202) where an ORDER BY would not work correctly when used with a GROUP BY. This has been fixed in more recent versions, but you may want to try the following to see if you have a “faulty” MySQL version:

    CREATE TABLE a (id int auto_increment primary key, sorter char(5));
    INSERT INTO a VALUES (1, 'z'), (2, 'x'), (3, 'a'), (4, 'z');
    SELECT * FROM a GROUP BY id ORDER BY sorter;
    

    If the result set you get is not sorted by the sorter field, then you may want to consider upgrading your database server.

    If an upgrade is not possible, there is one easy workaround for the above:

    SELECT * FROM ( SELECT * FROM a GROUP BY id ) b ORDER BY sorter;
    

    … which in your case should be the following:

    SELECT * FROM 
    (
        SELECT 
                Log_Analysis_RecordsToSesions_dalhousie.sessionID, 
                (TIMEDIFF(
                        MAX(Log_Analysis_Records_dalhousie.date), 
                        MIN(Log_Analysis_Records_dalhousie.date) 
                )) as NewSessionLength
        FROM 
                Log_Analysis_RecordsToSesions_dalhousie, 
                Log_Analysis_Records_dalhousie
        WHERE
                Log_Analysis_RecordsToSesions_dalhousie.recordID = 
                Log_Analysis_Records_dalhousie.recordID
        GROUP BY
                sessionID
    ) dt
    ORDER BY NewSessionLength;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't dismiss this as a newbie question! It's not, I'm not, I've tried everything,
I don't know if this question is trivial or not. But after a couple
Don't overthink this - there's a very commonly used term and I ... have
I don't have much knowledge about the IPv6 protocol, so sorry if the question
Don't know if this has been asked before, so point me to another question
Don't have much to say, just can get into the event handler. XAML: <Grid>
Don't think my virtualhost is working correctly. This is what I have inside of
This could be a duplicate question, but I have no idea what search terms
Don't worry, I'm not going to ask that question, yet again... I am wanting
Don't know if this has been answered before. Have custom routes to users. If

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.