我要查询某个表的字段信息
要求是
此字段包含另外一个表中以个字段的内容
比如
1
中国人
美国人
日本人
日本
是中
禁用
2
中中国人人
美国人
日本人
本日本名
我是中国人
我查询的是1表,等到的记录应该 除了 '禁用' 都检索到

解决方案 »

  1.   

    select * from t1
    where not exists
    (select 1 from t2 where t2.n like '%'||t1.n||'%')
      

  2.   


    楼上逻辑错了,多了个not
      

  3.   


    SQL> select * from table1;
     
    NAME
    --------------------
    中国人
    美国人
    日本人
    日本
    是中
    禁用
     
    6 rows selected
     
    SQL> select * from table2;
     
    NAME
    --------------------
    中中国人人
    美国人
    日本人
    本日本名
    我是中国人
     
    SQL> 
    SQL> select *
      2  from table1 t1
      3  where exists(select * from table2 t2 where t2.name like '%'||t1.name||'%');
     
    NAME
    --------------------
    中国人
    美国人
    日本人
    日本
    是中
      

  4.   

    3楼你不能得到
    NAME
    --------------------
    中国人
    美国人
    日本人
    日本
    是中
    这个吧!!!
      

  5.   

    SQL> 
    SQL> create table table01( name varchar2(300));
    Table created
    SQL> insert into table01 values('中国人');
    1 row inserted
    SQL> insert into table01 values('美国人');
    1 row inserted
    SQL> insert into table01 values('日本人');
    1 row inserted
    SQL> insert into table01 values('日本');
    1 row inserted
    SQL> insert into table01 values('是中');
    1 row inserted
    SQL> insert into table01 values('禁用');
    1 row inserted
    SQL> commit;
    Commit complete
    SQL> create table table02( name varchar2(300));
    Table created
    SQL> insert into table02 values('中中国人人');
    1 row inserted
    SQL> insert into table02 values('美国人');
    1 row inserted
    SQL> insert into table02 values('日本人');
    1 row inserted
    SQL> insert into table02 values('本日本名');
    1 row inserted
    SQL> insert into table02 values('我是中国人');
    1 row inserted
    SQL> commit;
    Commit completeSQL> select * from table01;
    NAME
    ----------------------------------------------------
    中国人
    美国人
    日本人
    日本
    是中
    禁用6 rows selectedSQL> select * from table02;NAME
    -----------------------------------------------------
    中中国人人
    美国人
    日本人
    本日本名
    我是中国人SQL> select * from table01 a
      2  where exists(select 1 from table02 b
      3               where instr(b.name,a.name,1) !=0
      4              );NAME
    -----------------------------------------------------
    中国人
    美国人
    日本人
    日本
    是中SQL> drop table table01;
    Table droppedSQL> drop table table02;
    Table droppedSQL> 
      

  6.   

    select a.cname from ,
    where a.cname like '%'||a1.tname||'%' ;select a.cname,a1.tname,instr(a1.tname,a.cname,1,1)from a,a1 where instr(a1.tname,a.cname,1,1)>0