请问:
看这段话:
EXISTS表示存在量词,带有EXISTS的子查询不返回任何实际数据,它只得到逻辑值“真”或“假”。当子查询的的查询结果集合为非空时,外层的WHERE子句返回真值,否则返回假值。问题:
where返回真值是什么意思 where语句不是用来约束查询时的返回行吗 怎么返回true 或 false呢
谢谢

解决方案 »

  1.   

    当子查询返回结果集合为非空时,exists(子查询)=true
    因此该行得以返回,因为 select 行 from 表 where true --此处true实为 exists(子查询)
    这和 select  行 from 表 where id=125 是一样的道理,因为当id=125时,实际上就是 where true.
    利用此类复合查询,可以获得比较巧妙的查询,如
    select id,name,pass from number a where exists(select 1 from msg where userid=a.id) --当存在此人录入的信息时获取行.
      

  2.   

    exists是判断行的存在   
    exists(   select   1   )   --返回真   
    exists(   select   1   where   1=2   )   --返回假  
      

  3.   

    select * from tablename where 1=1 
    1=1 就表示真拉。。所以返回表的所有记录
    select * from tablename where 1<>1
    1<>1 表示假拉。。一条记录都不返回! 
      

  4.   

    它的意思是说exists返回true or false。然后你的主要的where语句根据true or false 去执行。
      

  5.   

    当exists后面的子查询返回为True时就执行,否则就不执行
      

  6.   

    问题: 
    where返回真值是什么意思 where语句不是用来约束查询时的返回行吗 怎么返回true 或 false呢 
    谢谢
    ----------------------------------------------
    用途:指定一个子查询,检测行的存在。既然是检测行的存在,那就是符合楼主“where语句不是用来约束查询时的返回行吗”这一论断。
    以下就是判断brand表的brand_id只有在bom_mast表中存在的brand数据才会被取出。
    select * from brand
    where exists (select 1 from bom_mast where brand.brand_id = bom_mast.brand_id)
      

  7.   

    if exists(select * from table1 where 1=1)
    begin
    --条件成立的话就执行下面的语句
    end
    else
    begin
    --条件不成立的就执行这条语句
    end
      

  8.   

    select * from tablename where 1=1 
    1=1 就表示真拉。。所以返回表的所有记录 
    select * from tablename where 1 <>1 
    1 <>1 表示假拉。。一条记录都不返回! 
    自己拿点数据一试就明白了
      

  9.   

    返回的条件都是差不多的 不过where里面是条件是否存在,而exists是执行是否存在