0

I'm working on a practice problem and trying to use the table alias in the ON field but it's not working.

SELECT c.code AS country_code, name, year, inflation_rate
FROM countries AS c
Join to economies (alias e)
  INNER JOIN economies AS e
    **ON c.code = e.code;**

here's the standard answer

SELECT c.code AS country_code, name, year, inflation_rate
FROM countries AS c
Join to economies (alias e)
  INNER JOIN economies AS e
    **ON countries_code = e.code;**

This is what I entered

The standard answer wants me to use "c.code" in the ON field but I tried to use the alias "country_code" instead, and it wouldn't return any results.

LenaLD
  • 85
  • 2
  • 11

1 Answers1

1

Column aliases defined in the SELECT cannot be used in the FROM (and hence not in subsidiary clauses such as ON) or WHERE clauses.

Some databases allow aliases in the GROUP BY and/or HAVING clauses. All (or almost all) allow them in the ORDER BY clause.

Where aliases are available is referred to as scoping.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786