Can you use an alias created in a SELECT statement outside that query?

  • Thread starter EdmureTully
  • Start date
  • Tags Tags
    Mysql
3 replies · 2K views · last reply
EdmureTully
Messages
20
Reaction score
0
If you rename an attribute or a relation with the keyword AS in MYSQL can you use the alias created outside the query where you renamed the attribute, also can you use the old name?
 
EdmureTully said:
If you rename an attribute or a relation with the keyword AS in MYSQL can you use the alias created outside the query where you renamed the attribute, also can you use the old name?

Not that I am aware of.
 
The database does not store aliases you used in some query.

also can you use the old name?
Interesting, I never tried that. It is not possible.

SELECT * FROM `tablename` AS t WHERE t.fieldname=1 -> works
SELECT * FROM `tablename` WHERE tablename.fieldname=1 -> works
SELECT * FROM `tablename` AS t WHERE tablename.fieldname=1 -> does not work ("Unknown column 'tablename.fieldname' in 'where clause'")
 
If you have some good reason for having external (global) aliases to columns or tables then you can create a view
 
Last edited: