mysql查询中的错误 - 内部连接在哪里

时间:2011-10-26 02:37:15

标签: mysql sql mysql-error-1064

我收到了这个错误:

for the right syntax to use near 'INNER JOIN oferta B ON A.oferta_id_oferta = B.id_oferta AND B.oferta = "design' at line 4

我不能在where子句中进行内连接?或存在此查询的其他问题?

UPDATE `oferta_has_tags` A
    SET fraccao = "1/7"
    WHERE (
    INNER JOIN oferta B
    ON A.oferta_id_oferta = B.id_oferta
    AND B.oferta = "designer"
    AND B.estado = 0)

2 个答案:

答案 0 :(得分:1)

将其表示为简单的IN

UPDATE oferta_has_tags
SET fraccao = '1/7'
WHERE oferta_id_oferta IN (
    SELECT id_oferta 
    FROM oferta
    WHERE oferta = 'designer'
    AND estado = 0)

另外,将双引号(")更改为单引号(') - 使用双引号会导致错误

答案 1 :(得分:1)

查询错误。它必须有SELECT和FROM子句:

必须是这样的:

  

更新oferta_has_tags A       SET fraccao =“1/7”       WHERE id =(SELECT id FROM yourtable WHERE something = somevalue)

确保子查询应该返回1个值。如果要使用上述查询更新多个记录,请将“=”替换为“IN”。像这样:

  

更新oferta_has_tags A       SET fraccao =“1/7”       WHERE id IN(SELECT id FROM yourtable WHERE something = somevalue)

希望它有所帮助...