如何更正此SQL连接的相关名称?

我需要一个连接,从两个不同的表中产生三个具有相同名称的字段.当我尝试运行我的SQL查询,VS给我以下错误.

The objects “Politicalfigures” and “Politicalfigures” in the FROM clause have the same exposed names. Use correlation names to distinguish them.

我一直在尝试使用“AS”来区分这些字段,但是我没有找到一个可行的解决方案.这是我正在运行的SQL查询

SELECT Countries.Name AS Country,Politicalfigures.Name AS President,Politicalfigures.Name AS VicePresident FROM Countries
LEFT OUTER JOIN Politicalfigures ON Countries.President_Id = Politicalfigures.Id
LEFT OUTER JOIN Politicalfigures ON Countries.VicePresident_Id = Politicalfigures.Id

如果从代码中不明显,这些是表.

>国家:Id,Name,President_Id,VicePresident_Id.
>政治图:Id,Name.
>参加表:国家,总统,副总统

(请注意,我的应用程序中的表和字段具有不同的名称,我将它们进行概括,以使此示例更清晰,并希望与其他人更相关.)

(我使用的工具是Visual Web Developer 2010 Express和sql Server 2008 Express.)

解决方法

为每个参考政治图则使用表别名:
SELECT 
  Countries.Name AS Country,P.Name AS President,VP.Name AS VicePresident
FROM
  Countries
  LEFT OUTER JOIN Politicalfigures AS P ON Countries.President_Id = P.Id
  LEFT OUTER JOIN Politicalfigures AS VP ON Countries.VicePresident_Id = VP.Id

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 'EastRiver' 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...