SQL Query to update and insert a new row at a time

I have a condition where I need to check if the data is already exist in the database or not.  If it is already exist in the database then that row needs to updated  and insert one more row at the same time of the condition matched, Means the data is exist . And if the data is not present in the database then need to create a new row.   So I need a single SQL query where I can execute the UPDATE and INSERT at a time.   TIA
2 answers

Hi Monalisha,

I would not advise using a SQL query to insert any data into the database with a Mendix database. Mendix objects has an unique ID that is generated by the runtime. Adding any objects, other than through the runtime will cause issues.

Rather use a microflow that first attempts to retrieve your desired object and then, if it is not found, creates it.

Good luck



i sql 

Use the INSERT IGNORE command rather than the INSERT command. If a record doesn't duplicate an existing record, then MySQL inserts it as usual. If the record is a duplicate, then the IGNORE keyword tells MySQL to discard it silently without generating an error.


and here is also equivalent answer in oracle.


Oracle Equivalent to MySQL INSERT IGNORE? - Stack Overflow


hope this will help you.