Click here to Skip to main content
14,694,371 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to delete rows on the base of two different date old and update (18/2/2018 and 18/2/2019) come many time ...only old date rows delete ..there is not primary key on table

What I have tried:

I want to delete rows on the base of two date old and update (18/2/2018 and 18/2/2019) come many time ...only old date rows delete 
Posted
Updated 5-Dec-19 9:23am
Comments
Richard MacCutchan 5-Dec-19 13:52pm
   
Please show the code you are using, we cannot guess what it is.
Richard Deeming 5-Dec-19 13:54pm
   
There is nowhere near enough information in your question for anyone to help you.

Click the green "Improve question" link and edit your question to add:

* The relevant parts of your table's structure;
* The rules defining the rows you want to delete;
* A sample of what the data might look like before removing the duplicates; and
* What the sample data would like like after removing the duplicates.

If possible, create a SQL Fiddle[^] to demonstrate the problem, and post the link to it in your question.

1 solution

First, identify the rows you don't want:
Use GROUP BY to identify your "identical" rows as groups, and select only those groups which have more than one row.
You can then identify just the old rows from those groups by using EXCEPT to remove the latest value from each group (returning MAX date only from the eligible groups will help there) and use DELETE with a WHERE ... IN clause to remove the old stuff.

Build a demo table, and do it in stages until you have the "full SQL", using SELECT instead of DELETE until you are sure it works.

Sorry, but based on the lack of info we have so far, I can't be any more specific.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900