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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:46:28+00:00 2026-06-11T13:46:28+00:00

So i got this table: +—-+———————+—–+—————-+ | ID | WHEN | OFF | (other..stuff)

  • 0

So i got this table:

+----+---------------------+-----+----------------+
| ID | WHEN                | OFF | (other..stuff) |
+----+---------------------+-----+----------------+
| 1  | 2012-09-17 17:00:00 | 0   | anything1      |
| 2  | 2012-09-17 18:00:00 | 0   | anything2      |
| 3  | 2012-08-31 21:00:00 | 1   | blabla321      |
| 4  | 2012-08-31 18:30:00 | 1   | blab32121      |
+----+---------------------+-----+----------------+

I want to select all keys but:

  • Keys with off = 0 should be order by when ASC, and they should be
    displayed first
  • Keys with off = 1 should be order by when DESC, and they should be
    displayed after (at the end)

I tried something like this:

(SELECT * FROM `table` WHERE `off` = 0 ORDER BY `when` ASC)
UNION
(SELECT * FROM `table` WHERE `off` = 1 ORDER BY `when` DESC)

But it doesn’t work.

Also check:
https://i.stack.imgur.com/WWBEr.jpg

  • 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-06-11T13:46:29+00:00Added an answer on June 11, 2026 at 1:46 pm
    select *
    from `table`
    order by `off`,
        case `off`
            when 0 then timestampdiff(second, current_timestamp, `when`)
            when 1 then timestampdiff(second, `when`, current_timestamp)
        end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got this table: I want to choose the last two entries (the two
in my doctrine table i got this public function countHitsFor($object_id) { return $this->createQuery('s') ->select('COUNT(*)
Got this: Table a ID RelatedBs 1 NULL 2 NULL Table b AID ID
I've got this table with an int(11) column and hundreds of millions of rows.
So I've got this audit table, looks like this: USE [DatabaseName] GO /****** Object:
For example I got this 2 table dbo.fc_states StateId Name 6316 Alberta 6317 British
I've got this really basic table structure: Posts PostXTags PostTags There is a 1-n
Well ive got this code that creates a table from JSON data. If a
So I got this: HTML <table id=mytable> <tr> <td> </td> <td> </td> </tr> <tr>
I've got a situation like this: Table: FunTable ItemKey ItemName ItemPriceEffectiveDate ItemPrice 11 ItemA

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.