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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:20:22+00:00 2026-06-08T08:20:22+00:00

This is my situation. TABLE1: DOCUMENT_ID, GUID TABLE2: DOCUMENT_ID, FILE The tables are joined

  • 0

This is my situation.

TABLE1:

DOCUMENT_ID,
GUID

TABLE2:

DOCUMENT_ID,
FILE

The tables are joined by DOCUMENT_ID, meaning that TABLE2 can have one or many rows with the same DOCUMENT_ID.

My problem is that TABLE2 values for whole bunch of DOCUMENT_ID have same FILE values.

I need a SQL query that will get me all GUID and count how many rows in TABLE2 for this DOCUMENT_ID have EXACTLY THE SAME FILE value (so that I can copy the GUID to Excel).

Then I need to UPDATE TABLE2‘s FILE columns for these cases.

For instance if DOCUMENT_ID has three rows in TABLE2 with same FILE value, I need to update two of them by adding a postfix like FILEVALUE-1, FILEVALUE-2 and so on.

Hope I make sense.

To all experts thank you in advance.

  • 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-08T08:20:23+00:00Added an answer on June 8, 2026 at 8:20 am

    To get duplicates you might employ oldfashioned group by:

    select table1.guid, table1.document_id, table2.[file], count(*) cnt
      from table1
     inner join table2
        on table1.document_id = table2.document_id
     group by table1.guid, table1.document_id, table2.[file]
    having count (*) > 1
    

    To directly update duplicates, you might use CTE:

    ; with t2 as (
        select id, 
               [file],
               row_number() over (partition by document_id, [file]
                                  order by id) rn
          from table2
    )
    update t2
       set [file] = [file] + '-' + convert(varchar(10), rn - 1)
     where t2.rn > 1
    

    Note that I’ve added ID as a placeholder for primary key. You need a way to identify a record to be updated.

    There is live test @ Sql Fiddle.

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

Sidebar

Related Questions

I have three tables table1, table2, table3 with col1, col2 and identity ID column.
I have 2 tables, Table1 has a primary key 'CustomizationId', and Table2 has a
I have worked with various applications and encountered this situation many times. Until now
The situation is this: I have a div with overflow auto containing a table.
In this situation I have two models, Comment and Score. The relationship is defined
I have this situation: $(#button).toggle(function(){ $(#window).animate({top:'0%'},1000); },function(){ $(#window).animate({top:'-100%'},1000); }); but I need change it
I have this situation: http://jsfiddle.net/bRDgK/3/ In this situation I have a modal dialog with
I have this situation: { float foo[10]; for (int i = 0; i <
I have this situation where I want to display a list of Administration objects
We have this situation: Window Keyboard ^ ^ | / ApplicationWindow so class Window

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.