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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:19:16+00:00 2026-06-13T16:19:16+00:00

I am trying to update all records in my table. As I read through

  • 0

I am trying to update all records in my table. As I read through the records I need to update a column in the current record with a value from the NEXT record in the set. The catch is the updates need to be done in a specified order.

I was thinking of something like this …

Update t1
Set col1 = (select LEAD(col2,1) OVER (ORDER BY col3, col4, col5)
            from t1);

This doesn’t compile but you see what I’m driving at … any ideas ?

… update

This peice does run successfully but writes only NULLS

Update t1 A
Set t1.col1 = (select LEAD(col2,1) OVER (ORDER BY col3, col4, col5)
           from t1 B
           where A.col3 = B.col3 AND
                 A.col4 = B.col4 AND
                 A.col5 = B.col5);
  • 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-13T16:19:18+00:00Added an answer on June 13, 2026 at 4:19 pm

    This should do it:

    merge into t1
    using
    (
       select rowid as rid, 
              LEAD(col2,1) OVER (ORDER BY col3, col4, col5) as ld
       from t1
    ) lv on ( lv.rid = t1.rowid )
    when matched then 
      update set col1 = lv.ld;
    

    Not 100% sure if I got the syntax completely right, but as you didn’t supply any testdata, I’ll leave potential syntax errors for you to fix.

    You can also replace the usage of rowid with the real primary key columns of your table.

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

Sidebar

Related Questions

I am trying to update all records in a column so that they start
I'm trying to update all records in one table with the values found in
I'm trying to clear one column for all records in my table. For example,
I'm trying to do a single row insert/update on a table but all the
I'm trying to update a table based on the sum of values from another
I was trying to update approx 20,000 records in a table by using statements
I am trying to update a column in already exists MySQL table. The values
I'm trying to update a set of records ( boolean fields ) in a
Using Linq, trying to select all records not in my local set fails: var
I am trying to select all the records from a sqlite db I have

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.