philipcaplan Posted June 15, 2015 Posted June 15, 2015 (edited) I have a table with about 100,000 records. One of the fields in the table is called "DecimalNumber" (type is "Number"). There are many records (perhaps 10 to 20%) which have the same value in that field as another. Sometimes only 2 records have common values, sometimes more. What I want to do is to delete all records except one of each of those which share a value, thereby removing 'duplicates'. How do I achieve this? I assume a script will be needed, if so please can you give me the whole of that script. Many thanks in anticipation. Edited June 15, 2015 by philipcaplan
Chuck Posted June 15, 2015 Posted June 15, 2015 Off the top of my head, without testing it at all, which means don't just write it and trust it. Try it on a backup copy of your database first: Show All Records Sort Records [table::DecimalNumber] Go to Record/Request/Page [ First ] Loop If [ $_number = table::DecimalNumber ] Delete Record/Request [ No dialog ] Else Set Variable [ $_number ; table::DecimalNumber ] Go to Record/Request/Page [ Next ; Exit after last] End If End Loop
comment Posted June 15, 2015 Posted June 15, 2015 (edited) Try: # FIND DUPLICATES Enter Find Mode [ ] Set Field [ YourTable::DecimalNumber; "!" ] Perform Find [ ] # SORT BY THE DecimalNumber FIELD Sort Records [ Restore; No dialog ] # DELETE DUPLICATES Go to Record/Request/Page [ First ] Loop If [ YourTable::DecimalNumber ≠ GetNthRecord ( YourTable::DecimalNumber ; Get ( RecordNumber ) - 1 ) ] Go to Record/Request/Page [ Next; Exit after last ] Else Delete Record/Request [ No dialog ] End If End Loop # Show All Records Edited June 15, 2015 by comment
philipcaplan Posted June 15, 2015 Author Posted June 15, 2015 Hi comment. (1) Where you have "Get(RecordNumber)-1" are you assuming I have a 'unique serial number' called RecordNumber which I can use, because I'm afraid I don't. The dataset came from an outside tab-separated file which I opened in FMPro, and did not have any such numbering. (2) Or, is "RecordNumber" something that FMPro will understand as being an internal number in sequence? (3) If not, it seems to me that the only way a script can know if two records contain a duplicate value for DecimalNumber is if the Next Record's value for DecimalNumber is the same as the current record, in which case either one or the other can be deleted.
comment Posted June 15, 2015 Posted June 15, 2015 (1) Where you have "Get(RecordNumber)-1" are you assuming I have a 'unique serial number' called RecordNumber which I can use, because I'm afraid I don't. No. Get(RecordNumber) is a Filemaker function - look it up.
Newbies particle Posted April 27, 2019 Newbies Posted April 27, 2019 On 6/16/2015 at 4:21 AM, comment said: Try: # FIND DUPLICATES Enter Find Mode [ ] Set Field [ YourTable::DecimalNumber; "!" ] Perform Find [ ] # SORT BY THE DecimalNumber FIELD Sort Records [ Restore; No dialog ] # DELETE DUPLICATES Go to Record/Request/Page [ First ] Loop If [ YourTable::DecimalNumber ≠ GetNthRecord ( YourTable::DecimalNumber ; Get ( RecordNumber ) - 1 ) ] Go to Record/Request/Page [ Next; Exit after last ] Else Delete Record/Request [ No dialog ] End If End Loop # Show All Records Thanks. Work for my table.
Recommended Posts
This topic is 2310 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now