语法错误Mysql

时间:2012-02-17 15:55:43

标签: mysql

不知道为什么这不起作用 - 有人可以帮忙吗?

update c set c.images = ""
from j17_content c
inner join j17_jreviews_content rc on rc.contentid = c.id 
inner join j17_categories cat on cat.id = c.catid
where cat.path like "cakes%"
and c.created_by in (62,63,99)
and rc.email = 'email'

错误#1064 - 您的SQL语法出错;查看与您的MySQL服务器版本相对应的手册,以便在'第2行'中的rc.contentid = c.id附近的'j17_content c inner join j17_jreviews_content rc'附近使用正确的语法

更新:

正在尝试

UPDATE j17_content c SET c.images=''
inner join j17_jreviews_content rc on rc.contentid = c.id 
inner join j17_categories cat on cat.id = c.catid
where cat.path like 'cakes%'
and c.created_by in (62,63,99)
and rc.email = 'email'

仍在

错误#1064 - 您的SQL语法出错;检查与MySQL服务器版本对应的手册,以便在rc.contentid = c.id inner join j17_catego'第2行的'inner join j17_jreviews_content rc附近使用正确的语法

4 个答案:

答案 0 :(得分:1)

UPDATE不接受FROM

语法应为UPDATE j17_content c SET c.images="" INNER JOIN ...

答案 1 :(得分:1)

这是您的代码。

以这种方式尝试:

update j17_content c 
inner join j17_jreviews_content rc on rc.contentid = c.id  
inner join j17_categories cat on cat.id = c.catid 
where cat.path like 'cakes%'
and c.created_by in (62,63,99) 
and rc.email = 'email' 
set c.images = '';

这是更新加入

我有一个重构的查询版本

update  
(
    SELECT content_id id
    FROM j17_jreviews_content
    WHERE email = 'email'
) rc
inner join j17_content c USING (id)
inner join
(
    SELECT id catid
    FROM j17_categories
    WHERE created_by in (62,63,99)
    AND path like 'cakes%'
) cat USING (catid)
set c.images = '';

您将需要所涉及子查询的索引

ALTER TABLE j17_categories ADD INDEX created_by_path_id_ndx (created_by,path,id);
ALTER TABLE j17_jreviews_content ADD INDEX email_content_id_ndx (email,content_id);

答案 2 :(得分:0)

将单引号(“)替换为单引号(')

答案 3 :(得分:0)

很抱歉这不是你们建议的方式 - 但是我得到了一个ID列表并使用所有ID的in语句中没有连接来更新它们