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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:56:02+00:00 2026-06-13T17:56:02+00:00

I am trying to do some SQL working with Oracle I have a table

  • 0

I am trying to do some SQL working with Oracle

I have a table that contains text data, and an order list of numbers of how that text should appear, 1-27.

So:
Bonjour | 1
mon nom | 2
Jean P. | 3
Hello J | 4
Je suis | 5
is John | 6

Now I have to reorder the list numbers:
5 to number 2, and move 2 to 3, 3 to 4, 4 to 5, BUT NOT 5 to 6 or 6 to anything. Remember, this is a list to number 27.

So I'll have:
Bonjour | 1
mon nom | 2
Jean P. | 3
Hello J | 4
My name | 5
is John | 6

Does anyone know of a good way to go about doing this?

  • 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-13T17:56:03+00:00Added an answer on June 13, 2026 at 5:56 pm

    Something like:

    update foobar
       set sort_nr = case 
                       when sort_nr = 5 then 2
                       when sort_nr = 2 then 3
                       when sort_nr = 3 then 4
                       when sort_nr = 4 then 5
                       else sort_nr
                    end
    where sort_nr in (2,3,4,5);
    

    The else part in the case is not stricly necessary. But in case you forget the where clause it prevent accidental wrong updates.

    Here is an SQLFiddle example: http://sqlfiddle.com/#!4/52d50/1

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

Sidebar

Related Questions

I am trying to insert some text data into a table in SQL Server
I'm trying to simulate some code that I have working with SQL but using
Trying to have my PHP script return some SQL table queries. Here's my script
I have some working code that uses a SQL select statement within it. As
I have some SQL that gets a few details about a table. SELECT Column_Name,
I have some troubles trying to move data from SQL Server 2000 (SP4) to
I'm trying to rewrite some old SQL into LINQ to SQL. I have a
I am trying to do some text formatting with sql (MS SQL server 2008).
I'm working with a logfile that records data every 10 minutes. I'm trying to
I am working with some legacy SQL that is not really well written. There

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.