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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:21:51+00:00 2026-05-26T20:21:51+00:00

I have a small doubt, how to manage the following situation. In a DB

  • 0

I have a small doubt, how to manage the following situation.
In a DB table i save the relevant data in different columns and at the end i save the exact order in a column called position.
This table is binded to a grid. Now I’m implementing the functionality that will make change the position to the rows, but I need still to update the DB. I was asking what is the best practice or the most convenient way to achieve this?

And suggestion is welcome.

Example

Name position

abc 1

def 2

ghj 3

Now I click on the button and I get the following

Name position

def 1

abc 2

ghj 3

I hope that I have explained myself!

Based on the comments this is the real example:

TABLE1 with 3 columns ID1, ID2, POSITION
ID1 AND ID2 are FK’s and the table has a PK based on ID1 and ID2
When I select the data to display I use the following query
SELECT NAME, ETC FROM TABLE2 INNER JOIN TABLE1 ON ID1 = ID1 WHERE ID2 = 511
ORDER BY POSITION

Now I need to change the position on two elements so the row in TABLE1
for example 311,511,5 needs to became 311,511,4 and the row that was 433,511,4 needs to
became 433,511,5. The opposite.

I hope that this helped to clear out my question.

Cheers!

  • 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-26T20:21:51+00:00Added an answer on May 26, 2026 at 8:21 pm

    When you say: “change the position to the rows”, do you mean moving rows up and down through the table (relative to position ordering)?

    If so, to move the row up, you need to exchange the position with previous row. To move it down, you need to do the same with the next row. Depending on your particular SQL dialect, the syntax for exchanging values from different rows will probably look similar to this:

    UPDATE YOUR_TABLE
    SET position =
        CASE position
        WHEN 2 THEN 3
        WHEN 3 THEN 2
        END
    WHERE position IN (2, 3)
    

    This example moves the row 3 up and row 2 down. Replace 2 and 3 according to your needs…

    BTW, this should work even if there is a UNIQUE constraint on position (confirmed under Oracle).

    For more ideas, you may take a look at this question.

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

Sidebar

Related Questions

I am new to iphone.I have a small doubt (i.e),I have create a table
I have a small doubt I have following code bool res= false; if(cond1) {
I have a small doubt. I am trying to send json data to my
I have small doubt in CoVariance and ContraVariance.. See the Following Code.. interface IGetElement<out
I have small doubt in python. x = '' if x: print 'y' so,
Am Beginner to java.I have a small doubt while i am developing an application
I have a small architecture doubt about organizing code in separate functional units (most
Have a small doubt with static method. Documentation says that Static method can't access
I have a small doubt in CCAnimation. Is there any difference between the code1
I have a small doubt regarding network connection procedure in Android. My scenario is

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.