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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:47:56+00:00 2026-06-09T03:47:56+00:00

Is there a less ugly/more programmatic way to solve this: ORDER BY CASE WHEN

  • 0

Is there a less ugly/more programmatic way to solve this:

ORDER BY CASE 
 WHEN lessonID = 'lesson_1' Then 1  
 WHEN lessonID = 'lesson_novid_1' Then 2 
 WHEN lessonID = 'lesson_2' Then 3 
 WHEN lessonID = 'lesson_novid_2' Then 4 
 WHEN lessonID = 'lesson_3' Then 5 
 WHEN lessonID = 'lesson_novid_3' Then 6 
 WHEN lessonID = 'lesson_4' Then 7 
 WHEN lessonID = 'lesson_novid_4' Then 8 
 WHEN lessonID = 'lesson_5' Then 9 
 WHEN lessonID = 'lesson_novid_5' Then 10 
 WHEN lessonID = 'lesson_6' Then 11 
 WHEN lessonID = 'lesson_novid_6' Then 12
 WHEN lessonID = 'lesson_7' Then 13 
 WHEN lessonID = 'lesson_novid_7' Then 14
 WHEN lessonID = 'lesson_8' Then 15
 WHEN lessonID = 'lesson_novid_8' Then 16
 WHEN lessonID = 'lesson_9' Then 17
 WHEN lessonID = 'lesson_novid_9' Then 18
 WHEN lessonID = 'lesson_10' Then 19
 WHEN lessonID = 'lesson_novid_10' Then 20
 WHEN lessonID = 'lesson_11' Then 21
 WHEN lessonID = 'lesson_novid_11' Then 22 
 WHEN lessonID = 'lesson_12' Then 23 
 WHEN lessonID = 'lesson_novid_12' Then 24
End 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-09T03:47:58+00:00Added an answer on June 9, 2026 at 3:47 am

    Try to find the number and cast it to an integer:

    ORDER BY
        CAST(REPLACE(REPLACE(lessonID, 'lesson_', ''), 'novid_', '') AS INT),
        lessonID
    

    See it working online: sqlfiddle

    Note that this query will not be able to use an index to perform the ordering. You could consider using a computed column and indexing it to improve the performance.

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

Sidebar

Related Questions

Is there a less brute-force way to do this? #!/bin/ksh THIS_SCRIPT=$(/usr/bin/readlink -f $(echo $0
Is there more elegant (less code) way of find a matrix OUT, with colSums(OUT)<=a
I was wondering if there is a less intrusive way to analyze a running,
There are more or less straightforward ways to emit or listen signals of existing
Is there a way to make mercurial use less to show me the logs/diffs/whatever
Is there anything that is more powerful than a finite automaton but less powerful
Is there a less verbose alternative to this: for x in xrange(array.shape[0]): for y
As you probably know, there is a relatively simple way how to, more or
Although appengine already is schema-less, there still need to define the entities that needed
Is there CSS Meta Framefork for ASP.NET? Something like LESS or xCSS.

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.