Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
No Duplicates
Message
 
 
À
30/04/2010 14:23:59
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Divers
Thread ID:
01462570
Message ID:
01462575
Vues:
79
This message has been marked as a message which has helped to the initial question of the thread.
>Hello All!1
>i have this table that has dupllicates and i want to delete all the duplicatates an be only left with one oof the duplicated record. During that time i realized i dint know an SQL that could say that so decided to do an sql using the no duplicated. but then that only works for indexed records an will not work for everything in a TAble. So is there another way i can express what i want to the DAtabase?

T-SQL solution for SQL Server 2005+
;with cte as (select *, row_number() over 
(partition by Address_ID, guest_no order by Last_Mod desc) as Row, 
count(*) over (partition by Address_ID, guest_no) as cnt from
AddLink) 

delete from cte where cnt > 1 and row > 1
-------------------------------------------------------------
T-SQL 2000/VFP9 solution:
delete A from AddLink A inner join 
(select max(AddLink_ID) as MaxID, Address_ID, guest_no
from AddLink group by Address_ID, guest_no having count(*) > 1 ) Dups
on A.Address_ID = Dups.Address_ID and A.guest_no = Dups.Guest_No
and A.AddLink_ID < Dups.MaxID
to keep the latest record.

I hope you can adapt the second solution for your table names/fields.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform