FAQs Categories
Client Server Commands
Database Structure
Table Types or Storage Engines
SQL Statements
Table Joins
Funtions and Operators
Tricky Select Queries
Speed Up Queries
Data Back Up
General Questions
1PLs Company - #1Payday.Loans Agency - Loans online and near me $100-$2500 (Same Day)
Powered by MySQL
Home / SQL Statements / Question No: 212

What does alias means in MySQL?

Answer No: 212

When you join tables, it's often the case that the tables contain columns with the same names. If you refer to such a column in the query, it's ambiguous which table the column reference applies to. This ambiguity usually can be addressed by qualifying column names with table names. However, if you join a table to itself, even the table name is ambiguous and it's necessary to use aliases to disambiguate table references.

In SELECT query, output column names, by default, are the same as the column or expression selected. To rename a column, provide an alias following the column in the output list:

mysql> SELECT 1 AS One, 2+3 'Three Times Two';
| One | Three Times Two |
|   1 |               5 |
1 row in set (0.05 sec)

Here is another example:

mysql> SELECT Country.Name AS CountryName, City.Name AS CityName FROM Country, City
       WHERE Country.Code = CountryCode;

Columns aliases are used as follows:

  • The keyword AS is optional.
  • An alias may be quoted. If it consists of multiple words, it must be quoted.
  • You can refer to a column alias elsewhere in the query, in the GROUP BY, HAVING, or ORDER BY clause.  However, you cannot refer to aliases in the WHERE clause.

Related MySQL FAQs to the Above FAQ

What-does-SQL-Expressions-mean-in-MySQL What does SQL Expressions mean in MySQL?

How-to-use-numeric-expressions-in-MySQL How to use numeric expressions in MySQL?

How-to-use-string-expressions-in-MySQL How to use string expressions in MySQL?

How-to-manage-case-sensitivity-in-string-comparisons How to manage case sensitivity in string comparisons?

How-to-use-LIKE-pattern-matching-operator How to use LIKE pattern-matching operator?

How-to-use-date-or-temporal-expressions How to use date or temporal expressions?

What-does-NULL-value-mean-in-MySQL What does NULL value mean in MySQL?

How-to-use-comments-in-SQL-statements How to use comments in SQL statements?

How-to-validate-user-login-in-case-sensitive-manner How to validate user login in case sensitive manner?

What-is-difference-between-delete-and-truncate-statements-of-MySQL What is difference between delete and truncate statements of MySQL?

About FAQs: Recently Added FAQs

About MySQL FAQs: Site Map | Bookmark Us | Recommend this Site to Your Friend | Contact Us

Useful Links: | | | |

© 2023
All rights reserved.