Error Code: 1093. You can't specify target table '选课' for update in FROM clause 0.000 sec
时间: 2024-03-08 07:34:16 浏览: 123
This error occurs when you try to update a table that is also used in the SELECT statement of the same query. MySQL does not allow updating a table that is being used as a source for a subquery in the same statement.
To fix this error, you can use a temporary table or a subquery to select the data you want to update, and then perform the update on the original table. Here is an example:
UPDATE 选课
SET score = 90
WHERE student_id IN (
SELECT student_id
FROM (
SELECT student_id
FROM 选课
WHERE course_id = 1
) AS temp
);
In this example, we first select the student IDs of those who have taken course 1 using a subquery. Then, we update the score to 90 for those students in the original table 选课.
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)