CommencerCommencer gratuitement

Ambiguous column names

When joining tables, we use aliases in the SELECT statement to indicate the source tables of the selected columns, with each column name prefixed with the table name alias.

The following query joins the Players and PlayerStats tables to return total points by PlayerName and Country for all players from Australia.

SELECT PlayerName, p.Country,
         SUM(ps.TotalPoints) AS TotalPoints  
FROM PlayerStats ps
INNER JOIN Players p
   ON ps.PlayerName = p.PlayerName
WHERE p.Country = 'Australia'
GROUP BY p.PlayerName, p.Country

Copy and paste the query into the console and select Run Code to view the results. The query returns an error which includes the words ... Ambiguous column name...

Fix the query and run it. What was wrong with the original query?

Cet exercice fait partie du cours

Improving Query Performance in SQL Server

Afficher le cours

Exercice interactif pratique

Passez de la théorie à la pratique avec l’un de nos exercices interactifs

Commencer l’exercice