能否请您查看此代码?我收到此错误,但不确定是什么原因导致的:
')'附近的语法不正确。
select *
from
(select distinct
sar90.code, sar90.state, sar90.county,
sabet.code, sabet.state, sabet.county
from
[dbo].[sarshomari_90] as sar90,
[dbo].[Fixed] as sabet
where
sar90.county = sabet.county
and sar90.state = sabet.state
and sar90.state = N'kerman')
最佳答案
您需要为子查询加上别名。但是,您不需要为此使用子查询。您可以直接使用SELECT DISTINCT
。另外,请avoid using old-style JOIN
syntax并使用显式的JOIN
声明。
但是,如果您希望使用子查询,则您的列必须具有唯一的名称。通过添加唯一的别名来做到这一点。
select *
from(
select distinct
sar90.code as code1,
sar90.state as state1,
sar90.county as country1,
sabet.code as code2,
sabet.state as state2,
sabet.county as country2
from [dbo].[sarshomari_90] as sar90
inner join [dbo].[Fixed] as sabet
on sar90.county = sabet.county
and sar90.state = sabet.state
where
sar90.state = N'kerman'
)t