How to quickly delete Repeated Records of access fields Delphi/Windows SDK/API
Http://www.delphi2007.net/DelphiDB/html/delphi_20061223120244146.html
I have an access data table as follows:
ID name score
1. Old Zhang 80
2 Wang erxiao 70
3. Old Zhang 80
4 Li xiao 90
================================
Now I want to delete records with duplicate field names to achieve the following results:
ID name score
1. Old Zhang 80
2 Wang erxiao 70
4 Li xiao 90
How can access be operated in Delphi as quickly as possible?
I checked csdn and saw a person using the expression"
This is recognized as the fastest SQL statement for deleting duplicate records:
Delete from EMP e where E. rowid> (select Min (X. rowid) from emp x where X. emp_no = E. emp_no );"
What should I do as quickly as possible?
Please provide ideas
There seems to be no good way to solve this problem,
Do this,
Function getdelreocrdsid: string;
VaR
Midstr, resultstr: string;
Begin
With adodataset do
Begin
If active then active: = false;
Commandtext: = 'select * from EMP order by [name] ASC '; // be sure to sort
Open; midstr: = ''; resultstr: = '';
While (not EOF) Do
Begin
If trim (midstr) = trim (fieldbyname ('name'). asstring) then
Resultstr: = resultstr + fieldbyname ('id'). asstring + ',';
Else midstr: = fieldbyname ('name'). asstring;
Next;
End;
If result <> ''then
Result: = copy (resultstr1, length (resultstr)-1)
Else result: = '-1'
Close;
End;
End;
Procedure deleteselectrecord;
Begin
With adocommand do
Begin
Commandtext: = 'delete from EMP where ID in ('+ getdelreocrdsid + ')';
Execute;
End;
End;