1.
select distinct top 2 * from tb1 A,tb2 B where A.id=B.id order by newid()这句会报这种错误:如果指定了 SELECT DISTINCT,那么 ORDER BY 子句中的项就必须出现在选择列表中。请问要怎么改????
2.
select distinct top 2 * from tb1 A,tb2 B where A.id=B.id and A.xx='aa' order by newid()
union
select distinct top 3 * from tb1 A,tb2 B where A.id=B.id and A.xx='bb' order by newid()
这样也会是错误的.请问order by newid()能不能和union ,distinct 一起连用.......
谢谢了..........
select distinct top 2 * from tb1 A,tb2 B where A.id=B.id order by newid()这句会报这种错误:如果指定了 SELECT DISTINCT,那么 ORDER BY 子句中的项就必须出现在选择列表中。请问要怎么改????
2.
select distinct top 2 * from tb1 A,tb2 B where A.id=B.id and A.xx='aa' order by newid()
union
select distinct top 3 * from tb1 A,tb2 B where A.id=B.id and A.xx='bb' order by newid()
这样也会是错误的.请问order by newid()能不能和union ,distinct 一起连用.......
谢谢了..........
select distinct top 2 * from tb1 A,tb2 B where A.id=B.id order by newid()这句会报这种错误:如果指定了 SELECT DISTINCT,那么 ORDER BY 子句中的项就必须出现在选择列表中。请问要怎么改????newid()是函数.
order by后面必须更一个字段名或...,newid()并不在你的select选项中.
这样是正确的啊.....怎么解释?????
还有union ????
大家来接分,今天接贴
http://community.csdn.net/Expert/topic/5128/5128233.xml?temp=.6066248
http://community.csdn.net/Expert/topic/5128/5128222.xml?temp=.7657587
declare @ta table(id varchar(20))
insert @ta
select 123123564564 union all
select '中国人万岁' union all
select 'adfadfa1213'union all
select 15.6select * from(select top 1 * from @ta order by id asc)b
union all
select * from(select top 1 * from @ta order by id asc)a(所影响的行数为 4 行)id
--------------------
123123564564
123123564564(所影响的行数为 2 行)