当前位置:网站首页>MySQL multi table Association delete / update
MySQL multi table Association delete / update
2022-07-21 23:44:00 【The test is super standard】
During daily testing , You need to connect other tables and delete some dirty data , Write according to the normal query , Write delete statements like this :
DELETE from `order`
where id in (SELECT o.id from `order` o LEFT JOIN customer c on o.customer_id =c.id where o.customer_id is not null and c.id is null);
then … You can’t specify target table ‘order’ for update in FROM clause
intend : Not first select Give some values in the same table , Again update This table , That is, you can't update the value of a field based on the value of a field .
ok ~~~
Baidu has studied how to solve the problem of deleting multi table connections .
I'm also confused here , Why is the writing method of the update table associated with multiple tables reading 、 I can't see the introduction when watching the video ???
-- Delete order The data table , Be careful : Delete by alias
DELETE o
FROM `order` o
LEFT JOIN customer c ON o.customer_id = c.id
WHERE o.customer_id IS NOT NULL AND c.id IS NULL
-- Delete customer Table data , Be careful : Delete by alias
DELETE c
FROM `order` o
LEFT JOIN customer c ON o.customer_id = c.id
WHERE o.customer_id IS NOT NULL AND c.id IS NULL
-- At the same time to delete order、customer Table data , Be careful : Delete by alias
DELETE o,c
FROM `order` o
LEFT JOIN customer c ON o.customer_id = c.id
WHERE o.customer_id IS NOT NULL AND c.id IS NULL
By the way, I also studied how to update when connecting multiple tables :
UPDATE wx_customer wc
LEFT JOIN `order` o ON wc.id = o.wx_customer_id
SET o.wx_customer_id = NULL, wc.customer_id = NULL,wc.relate_wx_id = NULL
WHERE wc.id = "937680";
Here's a word : Update of multi table connection , You can update two tables at the same time ~
When Baidu studies , Some bigwigs also use aliases .... I don't use this writing method very much , I won't post it here
Summarize the rules ( Otherwise, it's a little hard to remember ~):
Whether it's SELECT、DELETE still UPDATE sentence , All of them are associated with multiple tables here .
边栏推荐
- sysstat安装并升级到11.5.5版本
- No idea about interface testing? An article to teach you how to handle the interview
- . WHL and Py installation method
- The company has only one test, but the leader asked me to test 10 projects
- jmeter
- 基础的md5加密
- Test case management tool recommendation
- 快速解决电脑无线网络无法连接问题
- [common interview questions of network protocol]
- 【小技巧】在当前目录下快速弹出cmd窗口且路径为当前路径的方法
猜你喜欢
How to do regression test
How to choose the model for remote real machine test?
win7系统忘记登录密码怎么办?(不用启动盘情况下)
使用postman批量运行接口时判断运行结果成功与否的常用断言
JMeter之BeanShell的变量使用方法
Using pointers to sort arrays
Install and upgrade sysstat to version 11.5.5
JMeter之聚合报告
Day02 test case knowledge summary (Part 1)
DataGrip 2021 使用设置,让你使用起来更丝滑
随机推荐
软件测试面试题与答案【一】
DataGrip 2021 使用设置,让你使用起来更丝滑
How can app testing ensure multi model coverage?
Real questions and answers of the latest written test for software testing engineers in 2022 (Sohu, Huawei, langang online)
jmeter
JMeter之WebService(soap)请求
[project acceptance] record the user's concerns of the latest project acceptance
Data driven testing of hand-in-hand teaching UI automation
JMeter之BeanShell生成随机汉字
How to evaluate the test quality?
Payment system test
Test triangulation, and use direct linear transformation method to calculate 3D point coordinates (3D reconstruction task2-1)
Programming technology of Servlet
[software test model evolution]
MySQL learning notes
postman newman jenkins
类的继承性实验报告
Day01 软件测试基础总结
MySQL学习笔记
软件测试常问面试题【二】