In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
In order to solve the problem of how to delete multi-table data in MySQL, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
What are the problems of deleting multi-table data by MySQL
1. Deletefromt1where condition
2. Deletet1fromt1where condition
3. Deletet1fromt1,t2where condition
4. Deletet1,t2fromt1,t2where condition
The first three are feasible, the fourth is not feasible.
In other words, it is impossible to delete multi-table data simply with delete statement, but you can establish cascade deletion and establish a cascade delete relationship between two tables, then you can delete data in one table while deleting related data in another table.
What are the problems of deleting multi-table data by MySQL
1. Delete all the records whose id values match in the data table T2.
DELETEt1FROMt1,t2WHEREt1.id=t2.id or DELETEFROMt1USINGt1,t2WHEREt1.id=t2.id
2. Find and delete the records that do not match in data table T1 and data table T2.
DELETEt1FROMt1LEFTJOINT2ONt1.id=t2.idWHEREt2.idISNULL or
DELETEFROMt1,USINGt1LEFTJOINT2ONt1.id=t2.idWHEREt2.idISNULL
3. Find the same recorded data from two tables and delete the data from both tables
DELETEt1,t2fromt1LEFTJOINt2ONt1.id=t2.idWHEREt1.id=25
Note that T2 in deletet1,t2from cannot be an alias.
For example, it is incorrect for deletet1,t2fromtable_nameast1leftjointable2_nameast2ont1.id=t2.idwheretable_name.id=25 to execute in the data (it is possible for MYSQL version not less than 5.0 in 5.0)
The above statement is rewritten as
It is incorrect for deletetable_name,table2_namefromtable_nameast1leftjointable2_nameast2ont1.id=t2.idwheretable_name.id=25 to execute in data (MYSQL version less than 5. 0 is allowed in 5. 0).
This is the answer to the question about how to delete multi-table data in MySQL. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.