Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement multi-table deletion operation in MySQL

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article shows you how to achieve multi-table deletion operation in MySQL, the content is concise and easy to understand, absolutely can make your eyes bright, through the detailed introduction of this article, I hope you can get something.

1. Delete all the records whose id values match in the MySQL data table T2.

DELETE T1 FROM T1 WHERE t1.id=t2.id or DELETE FROM T1 USING T1 WHERE t1.id=t2.id

2. Find and delete the records that do not match in MySQL data sheet T1 and data table T2.

DELETE T1 FROM T1 LEFT JOIN T2 ON t1.id=t2.id WHERE t2.id IS NULL or

DELETE FROM t1,USING t1 LEFT JOIN T2 ON t1.id=t2.id WHERE t2.id IS NULL

3. Find the same recorded data from two tables and delete the data from both tables

DELETE t1,t2 from t1 LEFT JOIN t2 ON t1.id=t2.id WHERE t1.id=25

Note that delete T1 and T2 in from cannot be aliases.

For example, delete T1 from table_name as T2 from table_name as T1 left join table2_name as T2 on t1.id=t2.id where table_name.id=25 is incorrect in data execution (MySQL version not less than 5.0 is OK in 5.0)

The above statement is rewritten as

It is incorrect for delete table_name,table2_name from table_name as T1 left join table2_name as T2 on t1.id=t2.id where table_name.id=25 to execute in the data (MySQL version less than 5.0 is OK in 5.0)

The above is how to implement multi-table deletion in MySQL. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report