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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:45:04+00:00 2026-06-15T21:45:04+00:00

The following code is producing a list with the non-expired rows on top, then

  • 0

The following code is producing a list with the non-expired rows on top, then the ones with unknown expiry date and at the end the already expired (all of them in ascending order). The problem is that I want the last block of already expired rows to be in descending order so it displays the rows that expired more recently on top of that block without altering the order of the other top blocks.

Basically, I am trying to find a way to incorporate two “ORDER BY” clauses within the same recordset…

Any ideas? Thanks

SELECT *
  FROM prueba 
 WHERE UPPER(CONCAT(Company,Deal,keywords,Type,Expiry,Name)) LIKE UPPER(%s) 
ORDER BY (CASE 
            WHEN prueba.Expiry = 'UNKNOWN' THEN 1 
            WHEN prueba.Expiry < CURRENT_DATE THEN 2 
          END)
       , prueba.Expiry ASC
  • 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-15T21:45:06+00:00Added an answer on June 15, 2026 at 9:45 pm

    Try this

    DEMO FIDDLE

    SELECT * FROM t
    order by case 
          when expiry = 'Unknown' Then 1 
          WHEN expiry >= CURRENT_DATE THEN 0 
          ELSE 2 END,
    CASE WHEN expiry >= CURRENT_DATE THEN expiry END,
    CASE WHEN expiry < CURRENT_DATE THEN expiry END desc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following code iterates through many data-rows, calcs some score per row and then sorts
The following code fails to compile, producing a Widget must be a non-abstract type
The following code is producing the error I stated in the title: $authkey =
The following code is producing a wrong conversion of a Timestamp ( 1350553368 ):
I have what is, to me, a confusing situation. The following code is producing
I've written the following bit of code that is producing a warning: initialization makes
I have the following code for producing a plot of data that extends two
I'm trying to implement a simple LinkedList The following code, producing this error: error:
The following code is producing a warning when I compile it on 32-bit systems:
I have the following code which is producing this error. I cannot understand why

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.