Get the App
SLTechnology News&Howtos  ›  Database  › 

How to implement conditional data insertion in mysql

Shulou Source: shulou.com Published: 2022-05-31 19:20:43 10月03日 Update

This article will explain in detail how to achieve conditional insertion of data in mysql. The quality of the article content is high, so Xiaobian shares it with you as a reference. I hope you have a certain understanding of relevant knowledge after reading this article.

The key is the MYSQL statement as follows,

Insert multiple records:

[sql]

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);

Insert single record:

[sql]

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);

About how to achieve conditional insertion data in mysql to share here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.

Tags: Data conditions content articles more knowledge articles good key multiple sentence quality reference help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Shulou Tech Info vpn Linux MariaDB