0

这是我尝试过的:

UPDATE tbl_questions 
JOIN (SELECT tbl_users.uid, tbl_users.is_spam
FROM tbl_users JOIN tbl_questions ON tbl_users.uid = tbl_questions.uid
)
SET question_type_id = 2
WHERE is_spam = 2;

我想将这些问题 question_type_id 更新为 2,其中用户表 is_spam = 2。我的 sql 写为错误Every derived table must have its own alias...

tbl_questions => uid, question_type_id,
tbl_users => uid, is_spam,
4

2 回答 2

1

子查询必须有别名。

UPDATE tbl_questions 
JOIN 
(
   SELECT tbl_users.uid, tbl_users.is_spam
   FROM tbl_users 
   JOIN tbl_questions ON tbl_users.uid = tbl_questions.uid
) sub_query_alias on sub_query_alias.uid = tbl_questions.uid
SET question_type_id = 2
WHERE is_spam = 2;

sub_query_alias在上面的查询中使用过。一个更简单的查询是

UPDATE tbl_questions q
JOIN tbl_users u ON u.uid = q.uid AND u.is_spam = 2
SET q.question_type_id = 2
于 2013-06-07T10:59:53.083 回答
0

请检查:-

UPDATE t1 SET t1.question_type_id = 2 from tbl_questions AS t1 JOIN tbl_users AS t2 ON t1.tbl_questions.uid = t2.uid WHERE t2.is_spam = 2;

于 2013-06-07T11:07:21.903 回答