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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:36:04+00:00 2026-05-25T01:36:04+00:00

I have a table of ordered data like this ID ORDER 12 1 13

  • 0

I have a table of ordered data like this

ID   ORDER
12     1
13     2
14     3
15     4
...
200    189
201    190
...

I would like to be able to update a few or all of their “order”s.
How should I do that?

For example, I might switch the ordering between ID=12 and ID=13 so it’d go like

ID   ORDER
12     2
13     1
14     3
15     4
...

This would just be a simple UPDATE TABLE SET ORDER=1 WHERE ID=13 SET ORDER=2 WHERE ID=12

But if I wanted to move ID=200 all the way to the top,..

ID   ORDER
12     2
13     3
14     4
15     5
...
200    190
201    1
...  

then everything would have to be updated..? How do I do that? Is there a better way? Decimals?

edit: I’m using MSSQL btw

edit:clarification of use: I have a table with a long list of URL links, and the order of those links matter. I want to be able to rearrange their order. I have a web page that retrieves that list from the db, displays the names as an unordered-list, and I can rearrange the items on that list. I’m stuck on how to get the newly ordered list’s order updated into the database.

  • 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-05-25T01:36:04+00:00Added an answer on May 25, 2026 at 1:36 am

    If you want to move an item up to the top, and update the order of all the other in a single statment, you can do the following:

    UPDATE MyTable
    SET    Order = (CASE Order WHEN 190 THEN 1
                               ELSE Order + 1
                               END)
    WHERE  Order BETWEEN 1 AND 190
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table called Orders in which the data looks like this: EMpID
I have a table with this kind of data in one of its column:
In MySQL I have one particular cell with data something like this 5,6,7,8,9 If
I have a MySQL query that produces this output ordered like this: Instead I'd
I have a table like this: ID Type UserID Timestamp 1 1 1000 1312389223
I have a table like this: id number otherfields ------------------------------------------- 664 48 aaa 665
I have table with 50 entries (users with such details like Name Surname Location
I have table rows of data in html being filled from a CGI application.
I have table with some fields that the value will be 1 0. This
I have some sprocs that need a temp table. In order not to hardcode

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.