有两张表 A, B
我现在想删除A
条件是 A.id = B.id
       A.name <> B.name
这个SQL语句怎么写?

解决方案 »

  1.   

    delete from A 
    where exists (select 1 from B where A.id = B.id and A.name <> B.name)
      

  2.   

    依照上面的执行后,
    出错:  ORA-00911: 无效字符这是什么意思啊?
    表中字段id和name都是有的啊不过这个"select 1"不明白.为什么是"select 1"啊?
      

  3.   

    同意 xiaoxiao1984(笨猫一只^_^) 的re:出错:  ORA-00911: 无效字符肯定是你自己抄错了;RE:不过这个"select 1"不明白.为什么是"select 1"啊?
    你也可以用2,3,4,* ,等等代替
    建议多看些基础知识吧!
      

  4.   

    SQL> select *from a1;        ID NA
    ---------- --
             1 A1
             2 A3
             3 A2
             4 B1SQL> select *from b1;        ID NA
    ---------- --
             4 B4
             3 B2
             2 B3
             1 B1SQL> delete from A1
      2  where exists (select 1 from B1 where A1.id = B1.id and A1.name <> B1.name);已删除4行。不知道楼主为什么不能执行,where exists (select 1 ...) 表明的是只要存在记录即可,可以select 1 ...或者select id ...或者其他的字段也可以