注册 登录
编程论坛 SQL Server论坛

三个不同条件的SQL语句合为一句

gupiao175 发布于 2008-07-09 11:11, 2083 次点击
select top 3 * from 表 where 类别='a'
select top 3 * from 表 where 类别='b'
select top 3 * from 表 where 类别='c'
  把这三条sql语句写成子查询。三个不同条件的SQL语句合为一句,帮帮忙!
这是网上看到的问题,网上很多人都说无法合为一句,不知道有没有高手能做到啊!
5 回复
#2
makebest2008-07-09 12:06
看不出有什么玄机,直接 UNION 就得了
#3
bygg2008-07-09 12:53
select top 3 * from 表 where 类别 in ('a','b','c')
#4
s0213712008-07-09 16:55
select top 3 * from 表 where 类别='a'
union
select top 3 * from 表 where 类别='b'
union
select top 3 * from 表 where 类别='c'
#5
smoon2008-07-18 10:47
select top 3 * from 表 where 类别='a' or 类别='b'or 类别='c'
1