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 929121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:07:02+00:00 2026-05-15T20:07:02+00:00

I have a table that is structured the following way (that i can’t change):

  • 0

I have a table that is structured the following way (that i can’t change):

EventName, LocalTime, Timezone

Data would be something like this:

Event1, 10:00, ET
Event2, 11:00, ET
Event3, 12:00, ET
Event4, 10:00, CT

how can i write a sql to sort this by actual time so result would be like:

Event1, 10:00, ET
Event2, 11:00, ET
Event4, 10:00, CT
Event3, 12:00, ET

Note that Event2 and Event4 happen at the same time so whichever comes first doesn’t matter.

My database is MySQL.

Again, I can not modify the source so I have to work with the data I’m dealt with

Thanks

  • 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-15T20:07:02+00:00Added an answer on May 15, 2026 at 8:07 pm

    Using a modern ver of mysql…

    Create table Tz_offsets:
    col Timezone, offset
    Data:
    ET, 0
    CT, 1
    
    
    Select EventName, LocalTime, Timezone
    From my_data_table 
    JOIN Tz_offsets On Tz_offsets.Timeszone = my_data_table.Timeszone 
    Where xxx
    Order By (LocalTime - offset)
    

    The key here is that Order By can take an expression.

    See http://dev.mysql.com/doc/refman/5.5/en/select.html

    Optimization

    In the above example, MySql will create a temp table. Depending on the size of your data, it might be much faster to pay a data insertion price vs a data retrieval price.

    To do so: add another column to the data table, “time_gmt” and then sort on the new column. But if you can’t, the above will work.

    If you can’t add the Tz_offsets table (if you can only use raw sql), then you have two choices:

    1. Add the Tz_offsets table as a temp table each time you run your sql. Your MySQL user will need temp table create permission.

    2. Do the tz offset lookups within the order by expression by using Case expression.

    Eg

    Select EventName, LocalTime, Timezone
    From my_data_table 
    Where xxx
    Order By (LocalTime - 
      (CASE Timezone WHEN 'ET' THEN 0 WHEN 'CT' THEN 1 WHEN 'PT' THEN 3 ELSE 0))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.