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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:31:11+00:00 2026-06-05T00:31:11+00:00

Duplicates in Table 1 are indentifies as follows; select quote_ref, count (*) from table

  • 0

Duplicates in Table 1 are indentifies as follows;

select quote_ref, count (*) 
from table 1 
group by quote_ref 
having count(*) > 1 

Now I want the eliminate the duplicates based on the 2 rules below .

Take the entry that has the Status= Complete
If none in complete status then take the one with max([created_date ])
Else Flag to look at ?

Suppose I need a CASE statement with a delete, but not sure how to construct ?

  • 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-05T00:31:13+00:00Added an answer on June 5, 2026 at 12:31 am

    For SQL Server 2005+, you can do the following:

    ;WITH CTE AS
    (
        SELECT  *, 
                ROW_NUMBER() 
                OVER(PARTITION BY quote_ref 
                     ORDER BY CASE WHEN [Status]='COMPLETE' THEN 1 ELSE 2 END, 
                     created_date DESC) RowNum
        FROM table1
    )
    DELETE FROM CTE
    WHERE RowNum != 1
    

    In this case, I’m assuming that the row that you don’t want to delete is the one with status = 'COMPLETE' or the one with the maximum created_date. If is the other way around, you can simply change the WHERE condition.

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

Sidebar

Related Questions

I'm trying to select duplicates from this table: snr zip 01 83 02 82
I want to do some quick inserts but avoid duplicates into a Table. For
I have a table transaction which has duplicates. i want to keep the record
Possible Duplicate: Writing an SQL query to SELECT item from the following table I
I have a table called _sample_table_delme_data_files which contains some duplicates. I want to copy
How do I remove duplicates from a table that is set up in the
RESOLVED! THANKS EVERYONE. I need to search for duplicates - table as follows: id,
I have a mysql table. How do I remove partial duplicates based on three
How can I select from two tables where table 1 returns 1 row and
How do I remove duplicates from the table where all the columns are significant

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.