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

The Archive Base Latest Questions

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

Note: If possible, I am looking for a pure SQL query solution so I

  • 0

Note: If possible, I am looking for a pure SQL query solution so I can run it in SQL Server Manager.

I had an error in my script which mean that some data that was meant to be entered once has been entered multiple times and now I need a way to either delete all but 1 entry PER company_id field or update the export column for 1 entry per company_id where:

short_desc the has more than one occurrence and
long_desc has more than one occurrence

My Data is structured like so:

   id  |  company_id  |  short_desc  |  long_desc  | export
    1       1234            word           text       0
    2       1234            word           text       0
    3       1234            word           text       0
    4       1234            word           text       0
    5       1234            word           text       0
    6       1234            word           text       0
    7       5678            another        foo        0
    8       5678            another        foo        0
    9       5678            another        foo        0
    10      5678            another        foo        0
    11      5678            another        foo        0
    12      5678            another        foo        0

I don’t mind which entries are updated / deleted as long as I only have 1 of each so in the example above, I would only have 2 entries left / marked as export=-1.

I have tried doing various things with sub selects and group by but I always need to end up grouping on id as well so I never get the duplicates. I don’t know if has just been a long morning but I can’t seem to think of a pure SQL way to do this and I would like to try avoiding writing a script to do it.

If the export flag is set, I will just delete where it equals 0.

I am using SQL Server 2008.

  • 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-01T08:20:30+00:00Added an answer on June 1, 2026 at 8:20 am
    update table set export = -1
    where table.id in 
    (
      select min(id) from table group by company_id,short_desc,long_desc
      having count(1) > 1
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please note the Edit below for a lot more information, and a possible solution
I am looking for something that works in SQL Server similar to the @
Is it possible to remove the whitespace surrounding an image in PHP? NOTE: to
Note that I am not asking which to choose (MVC or MVP), but rather
I've been looking at the decimal type for some possible programming fun in the
Possible Duplicate: HTML 5 Geo Location Prompt in Chrome I've been looking at geolocation
It's important to note that I'm not looking for a rounding function. I am
I'm looking for a higher-level system language, if possible, suitable for formal verification, that
Possible Duplicates: I am looking forward to call some javascript method from a java
I'm looking at all different sorts. Note that this is not homework (I'm in

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.