SQL更新内部加入与oracle请求的麻烦

时间:2014-10-10 11:38:27

标签: sql oracle join

Oracle数据库

大家好,我在使用oracle语法和内部联接时遇到麻烦我尝试了类似这样的东西,但它不起作用

“缺少SET关键字”

UPDATE table1 AS t1
INNER JOIN table2 AS t2 ON t1.id_description = t2.id_description  
SET field = '0.0.0.1.5.' 
WHERE t2.code='XXXX' AND t2.status IN ('VALUE1','VALUE2');
很多

3 个答案:

答案 0 :(得分:0)

UPDATE t1
SET t1.field = '0.0.0.1.5.'
From table1 AS t1
INNER JOIN table2 AS t2 ON t1.id_description = t2.id_description  
WHERE t2.code='XXXX' AND t2.status IN ('VALUE1','VALUE2');

答案 1 :(得分:0)

在SQL Server中有效,在oracle中还有另一种语法

UPDATE table1 t1
  SET field = '0.0.0.1.5.'
WHERE EXISTS (SELECT 'X'
                FROM table2 t2 
               WHERE t1.id_description = t2.id_description 
                 AND t2.code='XXXX' 
                 AND t2.status IN ('VALUE1','VALUE2'));

答案 2 :(得分:0)

试试这个:

UPDATE table1 t1
   SET field = '0.0.0.1.5.' 
 WHERE t1.id_description in (
         select t2.id_description 
           from table2 t2
          where t2.code='XXXX' 
            AND t2.status IN ('VALUE1','VALUE2')
       )