当前位置: 代码迷 >> Sql Server >> 这个SQL语句如何不能执行?关于union all
  详细解决方案

这个SQL语句如何不能执行?关于union all

热度:91   发布时间:2016-04-24 20:54:38.0
这个SQL语句怎么不能执行?关于union all
select count(*)
from
(
select id from tb
union all
select id from tb
)

这是怎么回事?

------解决方案--------------------
select count(*)
from
(
select id from tb
union all
select id from tb
)T     这样就可以了  括号后面字母随便你取
------解决方案--------------------
--括号里面的东东是一个子查询,是必须要加别名的。select count(*) from (...) as T
------解决方案--------------------

--楼主少了一个别名
select count(*)
from
(
select id from tb
union all
select id from tb
) a

------解决方案--------------------

select count(*)
from
(
select id from tb
union all
select id from tb
)a
--加个别名就可以

------解决方案--------------------
from后面一定要接个表名,你括号内其实是个数据集,你要给这个数据集起个名字才能查询

select count(*)
from
(
select id from tb
union all
select id from tb
) a