select xs_id, name from xs where not exist(
   select * from kc where not exist(
       select * from xs_kc where xs_ck.xs_id =xs.xs_id and xs_kc.kc_id=kc.kc_id
)

问  这句查询的是什么结果

解决方案 »

  1.   

    查询 xs 其中 xs_id 不在  kc和xs_ks中同时都存在的 哪些记录。
      

  2.   

    可以转换成如下的语句来理解:select xs_id
      from xs
     where xs.xs_id not in
           (select kc.id from kc, xs_kc where xs_kc.kc_id = kc.kc_id)
      

  3.   

    SQL> select * from xs;     XS_ID NAME
    ---------- --------------------
             1 jerry
             2 jack
             3 frankSQL> select * from kc;     KC_ID NAME
    ---------- --------------------
             2 clack
             5 jamesSQL> select * from xs_kc;     KC_ID      XS_ID
    ---------- ----------
             2          2SQL> select xs_id, name from xs where not exists(
      2    select * from kc where not exists(
      3        select * from xs_kc where xs_kc.xs_id =xs.xs_id and xs_kc.kc_id=kc.kc
    _id
      4  )
      5  ) ;未选定行SQL> select xs_id, name from xs where exists(
      2    select * from kc where not exists(
      3        select * from xs_kc where xs_kc.xs_id =xs.xs_id and xs_kc.kc_id=kc.kc
    _id
      4  )
      5  ) ;     XS_ID NAME
    ---------- --------------------
             1 jerry
             2 jack
             3 frankSQL>
      

  4.   

    select xs_id, name 
    from xs 
    where not exist( 
    select * 
    from kc 
    where not exist( 
    select * 
    from xs_kc 
    where xs_ck.xs_id =xs.xs_id --这个条件跨多个子查询,不能认识到XS表。
      and xs_kc.kc_id=kc.kc_id 

      

  5.   

    楼主,XS应该是学生表,KC应该是课程表吧!
    结果应该是选择了所有课程的学生id和name