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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:56:01+00:00 2026-06-10T00:56:01+00:00

I read ORDER BY condition and How to add condition in 'order by'? but

  • 0

I read ORDER BY condition and How to add condition in 'order by'? but these don’t answer to my issue.

I have 2 datetime columns called CREATION_DATE and UPDATE_DATE.

I want to sort (using ORDER BY clause) by :

  • CREATION_DATE if CREATION_DATE = UPDATE_DATE

    or

  • UPDATE_DATE in other case.

I wrote

SELECT * FROM Table1
ORDER BY
CASE Table1.CREATION_DATE
    WHEN Table1.CREATION_DATE = Table1.UPDATE_DATE THEN Table1.CREATION_DATE
    ELSE Table1.UPDATE_DATE
END ASC

but it does not work, I get an error at the = symbol.

I tried with other operators… Of course, I make mistake but I don’t know if is correct to use operators in WHEN statement.

Is not accepted operators in WHEN ?

Thank you

  • 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-10T00:56:02+00:00Added an answer on June 10, 2026 at 12:56 am

    try

    ORDER BY
    CASE WHEN Table1.CREATION_DATE = Table1.UPDATE_DATE
         THEN Table1.CREATION_DATE
         ELSE Table1.UPDATE_DATE
    END ASC
    

    or simpler

    ORDER BY Table1.UPDATE_DATE ASC
    

    since you want to order by UPDATE_DATE only if it is equal to CREATION_DATE. In that case you could order by UPDATE_DATE too. In other cases you want to oder by UPDATE_DATE. So just only order by that. It is the same.

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

Sidebar

Related Questions

I have read this in order to compile NH spatial for Nhibernate 3.1 http://build-failed.blogspot.it/2012/02/nhibernate-spatial-part-2.html
I've read several other questions about material in order to learn RoR. But my
To create a daemon I have read somewhere that in order to close all
Possible Duplicate: Order of condition checking? When i read some source codes, the if
I am using Tesseract 3.0 in order to read digits from a seven segment
I've been trying to pair NIO with multithreaded read handling in order to make
#!/bin/bash echo SCRIPT: $0 echo Enter Customer Order Ref (e.g. 100018) read P_CUST_ORDER_REF echo
I'm making a program which create a RAW socket in order to read all
I need to read the output from ffmpeg in order to even try the
My machine is little-endian (Intel byte order). I need to read a binary file

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.