select * from tab1 where not exists (select 1 from tab2 where tab1.col=tab2.col)
是什么意思?
 主要是select 1 from 看不懂?

解决方案 »

  1.   

    select * from tab1 where not exists (select 1 from tab2 where tab1.col=tab2.col)
    --看这个条件tab1.col=tab2.col,如果存在这样的数据子查询就返回1.
    --整个查询的意思就是在tab1中存在,在tab2中不存在的数据
      

  2.   

    select * from tab1 where not exists (select 1 from tab2 where tab1.col=tab2.col)
    因为你select 1 from tab2 where tab1.col=tab2.col这个查询不需要得到查询结果
    用select 1 的效率比select columnname高 所有就用select 1select 1 from table;与select anycol(目的表集合中的任意一行) from table;与select * from table 从作用上来说是没有差别的,都是查看是否有记录,一般是作条件查询用的。select 1 from 中的1是一常量(可以为任意数值),查到的所有行的值都是它,但从效率上来说,1>anycol>*,因为不用查字典表。scott@YPCOST> select 1 from dept;         1
    ----------
             1
             1
             1
             1
             1
             1
             1
             1
      

  3.   

     not exists  就是判断是否有结果,并不关心结果的内容,所以select 后面的字段都无所谓,只要越快越好
      

  4.   

    把tab1中所有与tab2的col对应列值相同的记录去除以后的所有记录
    select 1 from 就是说不关心具体的记录,只关心是否有结果。
      

  5.   

    select * from tab1 where not exists (select null from tab2 where tab1.col=tab2.col) select null 比 他select 1 效率更高,应为这样的话,I/O 更少!
      

  6.   

    select nul  和 select 1 速度应该是一样的.
      

  7.   

    关键是要理解exists,它是用来判断子查询(如:上述括号中的select 1.....)是返回有记录行,
    如果有记录行不管是一行还是多行,并且不管记录中字段内容如何),则条件返回为真,否则返回假。
      

  8.   


    select * from tab1 where not exists (select 1 from tab2 where tab1.col=tab2.col)select 1 1 不重要 只是匹配这个tab1.col=tab2.col 返回 true or false 
    随便你什么select 后面接什么都可以
      

  9.   

    不存在两个表匹配的意思。 
    跟 where tabl.col1 not in(select tab2.col1 from tab2) 意思一样
      

  10.   

    SQL> select 1 from t1;         1
    ----------
             1
    执行计划
    ----------------------------------------------------------
    Plan hash value: 3617692013------------------------------------------------------------------
    | Id  | Operation         | Name | Rows  | Cost (%CPU)| Time     |
    ------------------------------------------------------------------
    |   0 | SELECT STATEMENT  |      |     1 |     3   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS FULL| T1   |     1 |     3   (0)| 00:00:01 |
    ------------------------------------------------------------------Note
    -----
       - dynamic sampling used for this statement
    统计信息
    ----------------------------------------------------------
              0  recursive calls
              0  db block gets
              7  consistent gets
              0  physical reads
              0  redo size
            412  bytes sent via SQL*Net to client
            400  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              1  rows processedSQL> select null from t1;N
    -执行计划
    ----------------------------------------------------------
    Plan hash value: 3617692013------------------------------------------------------------------
    | Id  | Operation         | Name | Rows  | Cost (%CPU)| Time     |
    ------------------------------------------------------------------
    |   0 | SELECT STATEMENT  |      |     1 |     3   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS FULL| T1   |     1 |     3   (0)| 00:00:01 |
    ------------------------------------------------------------------Note
    -----
       - dynamic sampling used for this statement
    统计信息
    ----------------------------------------------------------
              0  recursive calls
              0  db block gets
              7  consistent gets
              0  physical reads
              0  redo size
            412  bytes sent via SQL*Net to client
            400  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              1  rows processedSQL>
      

  11.   

    select * from tab1 where not exists (select null from tab2 where tab1.col=tab2.col)
    1可能是第一条记录比较2表中的内容
      

  12.   

    select 1 ...用于不需要返回具体的查询字段时,提高速度使用的!通过布尔来快速查处数据条数
    我靠!这么多人抢分~
      

  13.   

    select 1 from 中1完全可以用*或表中其他字段代替,用1效率要高些
      

  14.   

    not exists 就是判断是否有结果,并不关心结果的内容,所以select 后面的字段都无所谓,select 1 from 中的1是一常量(可以为任意数值),查到的所有行的值都是它