有个判断条件是这样写的:
  if exists (select 1 from t1 inner join t2 on t2.a=t1.a where t1.name="")
如果条件满足,结果有一条记录就返回一条记录、一个字段,该字段的内容就是1,如果不满足条件就返回null。
我不明白为什么要这么写,直接select 一个常量

解决方案 »

  1.   

    1 =存在
    null =不存在
      

  2.   

    exists是判断表数据是否存在的意思,不管常量,标量,此句只是做判断,无须查出来那么多字段,你说呢?。。
      

  3.   

    用于exists判断,select的字段写什么都一样
      

  4.   

    EXISTS表示存在 只要为真就可以了 也可以 写2,3, 写任何常量都可以
      

  5.   

    是否存在这个结果集 
    (select 1 from t1 inner join t2 on t2.a=t1.a where t1.name="")
      

  6.   

    只要这个查询有结果 这个判断就为真  不必去写出这个结果集的 select 内容 
    当然也可以写出来
      

  7.   

    create table t1
    (
    id int,
    name varchar(10)
    )
    create table t2
    (
    id int,
    age int
    )
    insert into t1 values(1,'jim');
    insert into t1 values(2,'tom');
    insert into t2 values(1,24);declare @n int
    select @n = 1 from t1,t2 where t1.id = t2.id and t1.name = 'jim'
    if(@n = 1)
    begin
    select * from t1
    end
    else
    begin
    select * from t2
    end