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

  • Home
  • SEARCH
  • 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 745941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T09:38:29+00:00 2026-05-14T09:38:29+00:00

I have got a table which contains 5 column and query requirements: update row

  • 0

I have got a table which contains 5 column and query requirements:

update row no 8 (or id=8) set its column 2, column 3's value
            from id 9th column 2, column 3 value.

Means all value of column 2, 3 should be shifted to column 2, 3 of upper row (start from row no 8) and value of last row’s 2, 3 will be null

For example, with just 3 rows, the first row is untouched, the second to N-1th rows are shifted once, and the Nth row has nulls.

 id  math  science sst hindi english
  1   11     12     13  14   15
  2   21     22     23  24   25
  3   31     32     33  34   35

The result of query of id=2 should be:

 id  math  science sst hindi english
  1   11     12     13  14   15
  2   31     32     23  24   25        //value of 3rd row (col 2,3) shifted to row 2
  3   null   null   33  34   35

This process should run for all rows whose id > 2

Please help me to create this update query

I am using MS sqlserver 2005

  • 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-14T09:38:30+00:00Added an answer on May 14, 2026 at 9:38 am

    I THINK what you are looking for is something like…

    UPDATE t1
       SET 
          t1.math = t2.math,
          t1.science = t2.science,
          etc...
       FROM 
          YourTable t1, 
          YourTable t2
       WHERE 
          t1.id+1 = t2.id
    

    Notice the WHERE is for the first instance table’s ID +1 being equal to the ID in the second instance. So if on table 1 ID = 8, it will join to second instance’s ID = 9. At the end, if only 10 records, 10+1 would not have a match, and thus result in NULL.

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

Sidebar

Related Questions

I've got a table which contains a column named size. I want with a
I have got 2 tables: Contacts and Users . Contacts table contains user_id which
I've got a table which contains sensitive data and according to data protection policy
I have a .sqlite db which contains only one table. That table contains three
I have two columns syntax and query in my table Table1 . Syntax contains
I've got a table one column of which uses an NSPopUpButtonCell. Try as I
I have a table that has a column that contains links. Each cell in
I have some trouble when trying to update a table by looping cursor which
I have a table which contains the items the users of my game owns.
I have a table in my sql server 2005 database which contains about 50

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.