declare @a table (a int, b varchar(10))insert into @a values(1, '1')
insert into @a values(2, '2')
insert into @a values(1, '2')select * from @a where (a = 1 and b = '1') and (a = 2 and b = '2')
查询结果为什么是空?

解决方案 »

  1.   

    select   *   from   @a   where   (a   =   1   and   b   =   '1 ')   or (a   =   2   and   b   =   '2 ')
    你是要这个结果吧,肯定糊涂了脑袋 
      

  2.   

    select   *   from   @a   where   (a   =   1   and   b   =   '1 ')   and   (a   =   2   and   b   =   '2 ') 
    ==>
    select   *   from   @a   where   a   =   1   and   b   =   '1 '   and   a   =   2   and   b   =   '2 '我们就先把B的过滤条件给去掉:
    select   *   from   @a   where a = 1 and a = 2你一定是昏了,语句如何执行的知道么?
    这表示,针对表的每一行,它会去查询满足过滤条件的纪录,如果这一行满足条件,就返回。
    那么针对每一行,a可能等于1又等于2么,楼主你是在忽悠大家吧。 
      

  3.   

    select   *   from   @a   where   (a   =   1   and   b   =   '1 ')   or   (a   =   2   and   b   =   '2 ')