我尝试从结果中获取列,但是所有时间都有错误" Incorect语法附近')'"''即使我把Select *放在第一个选择中。我在SQL Management Studio上工作。我的代码看起来像
select ColumnResult from (
select col1 as ColumnResult, col2 as Column2Result, col3 as Column3Result
from SourceTable
except
select col1 as ColumnResult, col2 as Column2Result, col3 as Column3Result
from SourceTable2)
答案 0 :(得分:0)
您需要为子查询提供别名:
select ColumnResult from (
select col1 as ColumnResult, col2 as Column2Result, col3 as Column3Result
from SourceTable
except
select col1 as ColumnResult, col2 as Column2Result, col3 as Column3Result
from SourceTable2) AS Src
答案 1 :(得分:0)
您收到错误,因为每个表都有自己的别名,所以这样做
select A.ColumnResult from (
select col1 as ColumnResult, col2 as Column2Result, col3 as Column3Result
from SourceTable
except
select col1 as ColumnResult, col2 as Column2Result, col3 as Column3Result
from SourceTable2) as A