我维护的软件提供自编写sql语句查询,
现在有A,B两个表,
两个表有4个相同的字段,
以B表的记录为标准,以其中一个字段为索引,
查询A表中剩余3个字段与B表中不同的记录。
感觉光靠sql没法实现,得有循环才行,小弟愚笨,还请大神赐教,跪谢啦!或者直接查询A表记录中字段中的非法字符也行,限定数据只能是大写字母和数字。
select * from 表名 where 字段名 not like '%[0-9]|[A-Z]%' 
但是只有Oracle 10以上的版本支持正则表达式。所以求救啊。oraclesql正则表达式

解决方案 »

  1.   

    表A
    字段1 字段2 字段3 字段4
    123 A B C
    123 A A A
    123 B B B
    321 Q W E
    321 Q Q Q
    321 W W W表B
    字段1 字段2 字段3 字段4
    123 A B C
    321 Q W E筛选结果
    字段1 字段2 字段3 字段4
    123 A A A
    123 B B B
    321 Q Q Q
    321 W W W以B表为标准,从A表选出与B表字段1相同而其他字段不同的记录。
    或者说从A表中剔除与B表中指定的4个字段完全相同的记录。由于A表数据量相当大,是以时间条件限制查询范围的,B表的数据量也比较大,遍历B表逐一在A表中剔除运算量会较大。
      

  2.   

    SELECT * FROM A MINUS SELECT * FROM B
      

  3.   

    select * from A where not exists 
    (select 1 from B where A.字段1=B.字段1
    and A.字段2=B.字段2
    and A.字段3=B.字段3
    and A.字段4=B.字段4
    )
      

  4.   

    如果想用查询方式来过滤 就not in吧
    with t1 as
    (
         select 1 c1,'a' c2,'b' c3 from dual union all
         select 2 c1,'aa' c2,'bb' c3 from dual union all
         select 3 c1,'aaa' c2,'bbb' c3 from dual
    ),t2 as
    (
         select 1 c1,'a' c2,'b' c3 from dual union all
         select 3 c1,'aaa' c2,'bbb' c3 from dual
    )select *
    from t1
    where (c1,c2,c3) not in (select c1,c2,c3 from t2)
         c1    c2    c3
    --------------------------------
    1 2 aa bb
      

  5.   

     minus 不就可以了么我原来以为楼主是这个意思
    (a minus b)
    union all
    (b minus a)