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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:28:43+00:00 2026-06-01T04:28:43+00:00

enter code here My problem is this: in this database the junction table contains

  • 0

enter code hereenter image description here

My problem is this: in this database the junction table contains some rows where the kha_id and the icd_fk are the same. While it’s OK that kha_id appears in icd_junction more than once , it has to be with a separate icd_fk. I can run a query and get all of the ID#s and the codes which are listed more than once, but is there an industry-standard way of going about deleting all but one occurrence of each?

example: what i have is above

KHA_ID: 123456  V23 
        123456  V23
        123456  V24

I need one of the rows kha_id=123456 and ICD_FK=V23 taken out.
  • 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-01T04:28:45+00:00Added an answer on June 1, 2026 at 4:28 am

    This:

    DELETE j1
      FROM ICD_Junction AS j1
     WHERE EXISTS
            ( SELECT 1
                FROM ICD_Junction AS j2
               WHERE j2.KHA_ID = j1.KHA_ID
                 AND j2.ICD_FK = j1.ICD_FK
                 AND j2.ID < j1.ID
            )
    ;
    

    will delete, for each KHA_ID and ICD_FK, all but one relevant row of ICD_Junction. (Specifically, it will keep the one with the least ID, and delete the rest.)

    Once you’ve run the above, you should fix whatever code caused the duplication, and add a unique constraint to prevent this from happening again.

    (Disclaimer: Not tested, and it’s been a while since I last used SQL Server.)


    Edited to add: If I’m understanding your comment correctly, you also need help with the query to find duplicates? For that, you can write:

    SELECT KHA_ID,
           ICD_FK,
           COUNT(1)          -- the number of duplicates
      FROM ICD_Junction
     GROUP
        BY KHA_ID,
           ICD_FK
    HAVING COUNT(1) > 1
    ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

enter code here I have a table on SQL server 2005 with bigint primary
I check like this: enter code here var point = new g.LatLng(parseFloat(lat),parseFloat(lng)); var bounds
enter code here Hi All, I have a simple windows service application that connects
enter code here I have a ListView that have a different Layout XML for
I have <.ImageView> enter code here s(icons) in my android layout xml file, which
i have two dropdown list. first drop down:1 enter code here <form:select path=custName id=custName>
I let user enter some code in my Flex3 (Flash 10) app and I
I'm been stuck on this problem for a while and I'm pretty sure it
another weird problem with the iPhone SDK here. I have a UITableView which contains
I'm having some trouble updating a row in a MySQL database. Here is the

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.