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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:09:52+00:00 2026-05-26T11:09:52+00:00

I have a table of records, which has a self-relationship. Additionally – to make

  • 0

I have a table of records, which has a self-relationship.

Additionally – to make searching easier – I have a flag which determines that a record has been referenced and hence that row is now “obsolete” and is only there for audit purposes:

CREATE TABLE Records
(
  RecordID INT(5) NOT NULL,
  Replaces INT(5) NULL,
  Obsolete INT(1) NOT NULL
)

RecordID is the PK, Replaces links to a previous RecordID which has now been replaced, and Obsolete is redundant information which just says that another record has replaced this one. It just makes searching a lot easier. The table is very large. These are just 3 of the columns.

The only problem is: there was a typo in one of the queries in the system so for a small set of rows, the Obsolete value was not set to 1 (true).

This query will show all the records with Obsolete equal to 0 which should be equal to 1:

   SELECT *
     FROM Records AS rec1
LEFT JOIN Records AS rec2
       ON rec1.Replaces = rec2.RecordID
    WHERE rec2.RecordID IS NOT NULL
      AND rec2.Obsolete = 0;

Now I need to run an UPDATE to change all those req2.Obsolete from 0 to 1, but I’m not sure how to write a query with an INNER JOIN.

  • 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-26T11:09:52+00:00Added an answer on May 26, 2026 at 11:09 am

    You don’t need an inner join. Since your query already returns the records that need to be updated, just do this:

    Update Records
    set Obsolete=1 where
    RecordID in (
     SELECT rec2.RecordID     
            FROM Records AS rec1
    LEFT JOIN Records AS rec2
           ON rec1.Replaces = rec2.RecordID
        WHERE rec2.RecordID IS NOT NULL
          AND rec2.Obsolete = 0
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table in my database which has duplicate records that I want
I have a table which has records that contain a persons information and a
I have a database table A which stores records, A has a primary key
my table have several records which has the same MemberID. i want to result
I have a pretty large table (20M records) which has a 3 column index
I have a Skills table which has 14 records in it. It is structured
I have a Table which has the records of the down time of a
I Have a table called Table1 which has 48 records. Out of which only
i have a table phonebook which has 1.5M records, some of the records have
I have a table which has event-details. New records will be inserted to this

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.