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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:09:03+00:00 2026-05-31T09:09:03+00:00

I have to sort MySQL records based on a unix time field. However, some

  • 0

I have to sort MySQL records based on a unix time field. However, some records hold a value of 1 instead of time. Here’s how I want them sorted, assuming current time is 125:

127
130
132
133
1
1
1
1
124
122
119

As you can see, the top section is records in ASC order by the time field with the soonest time first, these are followed by all the records that are marked with 1 instead of a proper time, and then the records from the past in DESC order. Is this doable?

  • 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-31T09:09:04+00:00Added an answer on May 31, 2026 at 9:09 am

    You can do this with the following code:

    drop table if exists numbers;
    create table numbers ( value int );
    insert into numbers values 
    (119),(122),(124),(127),(130),(131),(1),(1),(1),(1);
    
    select 
        value 
    from numbers
    order by if( value = 1, 125, if( value > 125, 99999 - value, value ) )  desc
    

    which produces:

    value
    -----
    127
    130
    131
    1
    1
    1
    1
    124
    122
    119
    

    Jus replace all occurrences of 125 with the current time and `99999′ with the largest time value that you might encounter in your table.

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

Sidebar

Related Questions

I have a sort of unique situation....I want to populate a ModelChoiceField based of
I have some sort of recursive function, but I need to parse a string,
I have to sort out my data by some column, such that some specific
I have some sort of a design problem with my Django AJAX application. I
I have a database mysql and it contains 1000 records of people (Name, Age,
I have a table with about 3000 records that I query often. Does mysql
I have two tables in MySQL, one containing a field City and one containing
I have just added a null password field to a mysql table using this
I would like to calculate some sort of hash or checksum value for a
Let's say that I have a bunch of records in MySQL, something like this:

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.