现表 T1 有如结构:c_person  type  
  001       A    
  002       A     
  001       B        
  001       c
  001       d
  002       c把 c_person 中 type 为A 和C的记录找出来请问是否用 type ='A' or type='C' 就能满足条件了?

解决方案 »

  1.   

    create table person(c_person varchar(10),type varchar(10))
    insert into person
    select '001','A' union all
    select '002','A' union all
    select '001','B' union all
    select '001','D' union all
    select '002','C' union allSELECT * FROM person
    WHERE type='A' OR TYPE ='C' 
    SELECT * FROM person
    WHERE type IN ('A','C')
      

  2.   

    select * from person where type='A'
    union all
    select * from person where type='C'
      

  3.   

    declare @person table(c_person varchar(10),type varchar(10))
    insert into @person
    select '001','A' union all
    select '002','A' union all
    select '001','B' union all
    select '001','c' union all
    select '002','d' union all
    select '002','c'select *
    from @person
    where type='A' or type='C' --'c'和'C'默认不区分大小写
    --结果
    c_person type
    001         A
    002         A
    001         c
    002         c
    select *
    from @person
    where type='A' or type='C' COLLATE   Chinese_PRC_CS_AS   --'c'和'C'区分大小写
    --结果
    c_person type
    001          A
    002          A
      

  4.   

    SELECT * FROM person
    WHERE type='A' OR TYPE ='C' 
    SELECT * FROM person
    WHERE type IN ('A','C')
      

  5.   

    SELECT * FROM person
    WHERE type='A' and TYPE ='C'  
    把OR改成AND 会找什么呀
      

  6.   

    5楼最高效。
    IN 次之,OR 本人用的很少 经常查询造成不准确,最主要的是容易被人注入