How can I correct the correlation names on this sql join?

前端 未结 4 1275
时光取名叫无心
时光取名叫无心 2020-12-03 06:58

I need a join that yields three fields with the same name from two different tables. When I try to run my sql query, VS gives me the following error.

4条回答
  •  日久生厌
    2020-12-03 07:34

    You need to use AS on the tables to give them aliases:

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

提交回复
热议问题