FM.InsertRecordQueryIgnoreDuplicates
------------------------------------

Inserts a lot of records queried from a database.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [FM](component_FM.md) [FMSQL](component_FMSQL.md) | [6.0](newinversion60.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "FM.InsertRecordQueryIgnoreDuplicates"; InsertFileName; InsertTableName; FieldNames; QueryFileName; SQL Statement { ; Params... } ) 

**MBS**( **"FM.InsertRecordQueryIgnoreDuplicates";** /\* Inserts a lot of records queried from a database. \*/  
**$InsertFileName**; /\* The file name of where the insert table is inside. Can be empty to look for the table in all files.e.g. Get(FileName) \*/   
**$InsertTableName**; /\* The name of the table to insert record into.  
Can be ID of table, so we lookup name by ID.   
Can be result of GetFieldName() function as we remove field name automatically.e.g. "Assets" \*/   
**$FieldNames**; /\* A list of field names for the insert.  
Empty entries in the list are ignored.  
  
Can be ID of field, so we lookup name by ID.   
Can be result of GetFieldName() function as we remove table name automatically.e.g. "Model" \*/   
**$QueryFileName**; /\* The file name for the database to run the query against. Can be empty to look for the table in all files.e.g. Get(FileName) \*/   
**$SQL Statement**; /\* SQL Statement as a Text string \*/   
**$Params...**) /\* Optional; Pass here parameters.   
One parameter to this function for each parameter you want to pass to the SQL statement.e.g. 123 \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| InsertFileName | The file name of where the insert table is inside. Can be empty to look for the table in all files. | Get(FileName) |  |
| InsertTableName | The name of the table to insert record into.   Can be ID of table, so we lookup name by ID.    Can be result of GetFieldName() function as we remove field name automatically. | "Assets" |  |
| FieldNames | A list of field names for the insert.   Empty entries in the list are ignored.      Can be ID of field, so we lookup name by ID.    Can be result of GetFieldName() function as we remove table name automatically. | "Model" |  |
| QueryFileName | The file name for the database to run the query against. Can be empty to look for the table in all files. | Get(FileName) |  |
| SQL Statement | SQL Statement as a Text string |  |  |
| Params... | Pass here parameters.    One parameter to this function for each parameter you want to pass to the SQL statement. | 123 | Optional |

### Result

Returns OK or error.

### Description

Inserts a lot of records queried from a database.  
Same as [FM.InsertRecordQuery](FMInsertRecordQuery.md), but ignores duplicate records.  
On success returns the number of duplicate records instead of OK if there were any.  
This function allows to easily copy a lot of records from one table to another table.   
Copy can be from one database to other or within same database. Also from one table to other or within a table. Due to passing in new field names, you can even rearrange values from one column to other while copying. In the SQL you can use functions for sums or join data from several tables together to fill a new table. Filename parameters can be empty.  
Use [FM.ExecuteSQL.LastErrorMessage](FMExecuteSQLLastErrorMessage.md) and [FM.ExecuteSQL.LastError](FMExecuteSQLLastError.md) to see error message.  
Reports an error if field name list doesn't match column count of the query result.  
Does not copy text styles, only plain text for text fields.  
  
The duplicate check is based on FileMaker checking if a field is unique, e.g. the record ID.  
For inserting records from other database (e.g. MySQL), please use [SQL.InsertRecords](SQLInsertRecords.md) function.  
  
With plugin version 7.2 or later, you can specify fields and table via IDs and the plugin will lookup them for you at runtime. Table IDs and table names must be unique across all open files for this to work correctly.  
  
Please don't overload the function, so better work in blocks of e.g. 1000 rows at a time.  
  
This function takes variable number of parameters. Pass as much parameters as needed separated by the semicolon in FileMaker.  
Please repeat Params parameter as often as you need.  
### Examples

Copy records within one table in same file:

 MBS ( "FM.InsertRecordQueryIgnoreDuplicates"; ""; "Contacts"; "First¶Last¶Company"; ""; "SELECT \\"First\\", \\"Last\\", \\"Company\\" FROM Contacts" )  
Copy records from a table from one database to other (production to development)

 MBS ( "FM.InsertRecordQueryIgnoreDuplicates"; "ContactsDev.fmp12"; "Contacts"; "First¶Last¶Company"; "Contacts.fmp12"; "SELECT \\"First\\", \\"Last\\", \\"Company\\" FROM Contacts" )  
Copy data to other table:

 MBS ( "FM.InsertRecordQueryIgnoreDuplicates"; ""; "Test"; "FirstName¶LastName¶CompanyName"; ""; "SELECT \\"First\\", \\"Last\\", \\"Company\\" FROM Contacts" )  
Query sum of sales grouped by customers in a sales report table:

 MBS ( "FM.InsertRecordQueryIgnoreDuplicates"; ""; "SalesReport"; "SumSales¶CustomerID"; ""; "SELECT sum(\\"InvoiceTotal\\"), \\"CustomerID\\" FROM Clients, Invoices WHERE Invoices. CustomerID = Clients.CustomerID GROUP by CustomerID" )  
Copy two fields from one table to other:

 MBS ( "FM.InsertRecordQueryIgnoreDuplicates"; ""; "ASC Apple Script"; "Name¶Script"; ""; "select \* from \\"AppleScript\\"")  
### See also

- [FM.ExecuteSQL](FMExecuteSQL.md)
- [FM.ExecuteSQL.LastError](FMExecuteSQLLastError.md)
- [FM.ExecuteSQL.LastErrorMessage](FMExecuteSQLLastErrorMessage.md)
- [FM.InsertRecord](FMInsertRecord.md)
- [FM.InsertRecordQuery](FMInsertRecordQuery.md)
- [FM.InsertSetUpdateProgressDialog](FMInsertSetUpdateProgressDialog.md)
- [SQL.InsertRecords](SQLInsertRecords.md)

### Release notes

- **Version 16.1**
    - Rewrote [FM.InsertRecordQuery](https://www.mbsplugins.eu/FMInsertRecordQuery.shtml) and [FM.InsertRecordQueryIgnoreDuplicates](https://www.mbsplugins.eu/FMInsertRecordQueryIgnoreDuplicates.shtml) to use newer code base.

### Blog Entries

- [MBS FileMaker Plugin, version 16.1pr1](https://www.mbsplugins.de/archive/2026-02-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 6.2pr3](https://www.mbsplugins.de/archive/2016-04-05/MBS_FileMaker_Plugin_version_6/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 6.0pr7](https://www.mbsplugins.de/archive/2016-01-20/MBS_FileMaker_Plugin_version_6/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 18th January 2016 , last changed 29th January 2023

  
[FM.InsertRecordQuery](FMInsertRecordQuery.md) - [FM.InsertRecordTSV](FMInsertRecordTSV.md)

[HTML Version](FMInsertRecordQueryIgnoreDuplicates.shtml)