Example: MySQL inserts a record when the record does not exist. MySQL inserts the record if the record does not exist:
Example: insert multiple records
Suppose there is a clients table with the primary key of client_id, you can use the following statement:
Insert into clients
(Client_id, client_name, client_type)
SELECT supplier_id, supplier_name, 'Advertising'
FROM suppliers
WHERE not exists (select * from clients
Where clients. client_id = suppliers. supplier_id );
Example: insert a single record
Insert into clients
(Client_id, client_name, client_type)
SELECT 10345, 'IBM ', 'Advertising'
FROM dual
WHERE not exists (select * from clients
Where clients. client_id = 10345 );
Using dual as the table name allows you to directly keep up with the values of the fields to be inserted after the select statement, even if these values do not exist in the current table.