MySQL: Using Aliases & Old Names

  • Thread starter Thread starter EdmureTully
  • Start date Start date
  • Tags Tags
    Mysql
Click For Summary

Discussion Overview

The discussion revolves around the use of aliases and old names in MySQL queries, specifically focusing on whether aliases created with the AS keyword can be used outside the query and if old names can still be referenced. The scope includes technical explanations and practical applications of SQL syntax.

Discussion Character

  • Technical explanation, Debate/contested

Main Points Raised

  • Some participants assert that aliases created with the AS keyword in MySQL are not stored by the database and cannot be used outside the query.
  • One participant questions whether the old name can still be used after renaming, suggesting that it may not be possible based on their experience.
  • A participant provides examples illustrating that while using an alias works in certain contexts, referencing the old name in conjunction with the alias does not work, leading to an "Unknown column" error.
  • Another participant suggests that if there is a need for external or global aliases, creating a view could be a solution.

Areas of Agreement / Disagreement

Participants generally agree that aliases are not retained outside of the query context, but there is uncertainty regarding the use of old names after renaming. The discussion remains unresolved on whether old names can be referenced in all scenarios.

Contextual Notes

Limitations include potential misunderstandings of SQL behavior regarding aliases and old names, as well as the specific contexts in which certain queries may or may not work.

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?
 
Technology news on Phys.org
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:

Similar threads

  • · Replies 16 ·
Replies
16
Views
3K
  • · Replies 12 ·
Replies
12
Views
11K
  • · Replies 7 ·
Replies
7
Views
5K
Replies
3
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 9 ·
Replies
9
Views
5K
  • · Replies 4 ·
Replies
4
Views
8K
Replies
6
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 19 ·
Replies
19
Views
2K