I'm not sure how to resolve an ambiguous column reference when using an alias.
Imagine two tables a and b that have a column name . If I join these two tables and get the result, I donβt know how to refer to the name column for both tables. I tried several options, but none of them work:
Attempt 1
SELECT a.name, b.name FROM (a INNER JOIN b ON a.id = b.id) AS x
This does not work, since a and b are out of scope.
Attempt 2
SELECT xaname, xbname FROM (a INNER JOIN b ON a.id = b.id) AS x
SQL syntax does not work.
Attempt 3
SELECT x.name, x.name FROM (a INNER JOIN b ON a.id = b.id) AS x
This is simply ambiguous!
I have all of the ideas - any help would be greatly appreciated.
source share