Link to home
Get AccessLog in
Avatar of Paer Toernell
Paer ToernellFlag for Thailand

asked on

How to use alias in MYSQL searches?

I seen some hints that i can use something like alias in searches, like making a select statement becoming A. How is this done?

its from the question
Avatar of awking00
Flag of United States of America image

See attached example.
deal with your first question first.
Avatar of Paer Toernell


select A.col1, X.col2
from tableA A,
(select pk, col3 from tableB where col4 = 'Z') X
where =;
A is alias for tableA and X is alias for the subquery.

I still don't get it. Where is A assigned and where is X assigned?

in the syntax

from tableA A
is shorthand for
from tableA AS A

the text that follows the table name immediately if not a reserved word (e.g. WHERE, JOIN, LEFT, RIGHT ... ) is the alias by which the table is called in the rest of the SELECT statement

Regarding my first question - i stuck because i don't understand the answer, and i thought it be more correct to open up another question instead of creating a "sub" question. Probably the answer is correct, its just me who don't understand it. Therefore i choose to make a new question focusing on the "alias" part.
To add to virmajor's comment, the same is true for the subquery - (select ...) AS X.
Also, see my response to your earlier question.
I still must ask, will this AS make the an alias for the table or for the searchresult?
an alias causes the table or subquery to be referenced by the alias name within the query.

it does not create any permanent relationship or alternative name
The alias can be either for a table or a query, which I would call the search rather than searchresult. Also you do not need the word AS. If you follow the tablename or the query with anything other than a keyword, it will assume it is an alias.
Is the examples above for aliasing a table or a search?
it aliasing a table and a subquery in a query.

a "search" does not mean anything in SQL
Avatar of awking00
Flag of United States of America image

Link to home
This content is only available to members.
To access this content, you must be a member of Experts Exchange.
Get Access