create table ab ( A varchar(2), B varchar(2) )insert into ab values('a','1') insert into ab values('a','2') insert into ab values('a','3') insert into ab values('b','1') insert into ab values('b','2') insert into ab values('c','1') insert into ab values('c','2') insert into ab values('c','3') insert into ab values('c','4')select A,B from ab where B='1' or B='3'select A,B from ab where B in ('1','3')
from table1
where b in (1,3)
你们这样不是把b 1也查出来了吗
楼主意思应该是查询
B字段中所有值为 1和 3对应的值,也就是说同时有1和3如:a 1,a 3
不晓得楼主是不是这个意思
上面语句不加括号应该也行 OR 比 AND 优先级高
我承认这个能写出来,但是不能满足要求,你在你未知A字段中有那些数据的时候你怎么写?
http://community.csdn.net/Expert/topic/5486/5486258.xml?temp=.3580133
(
A varchar(2),
B varchar(2)
)insert into ab values('a','1')
insert into ab values('a','2')
insert into ab values('a','3')
insert into ab values('b','1')
insert into ab values('b','2')
insert into ab values('c','1')
insert into ab values('c','2')
insert into ab values('c','3')
insert into ab values('c','4')select A,B
from ab
where B='1' or B='3'select A,B
from ab
where B in ('1','3')
from table1
where b in (1,3)