Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Python Programs
    • Java Programs

MySQL Alias

by suresh

MySQL Alias keyword is to temporarily rename the column names or table names within a Database. Sometimes column names may not be user-friendly in real-time.

For example, we store the First Name as either FirstName or First_Name. When the user reads the data, it won’t be very pleasant to see the column heading like that. So, while we SELECT the data, we use this Alias to rename them as ‘First Name’ or ‘FIRST NAME’.

MySQL Alias Syntax

The basic syntax to write MySQL Table Alias Names is as shown below:

SELECT tab1.[Column Name 1], 
       tab1.[Column Name 2],..., 
       tab1.[Column Name N]
FROM [Table_Name] AS tab1

And the syntax to write MySQL Column Alias Names is as shown below:

SELECT [Column Name 1] AS Name, 
       [Column Name 2] AS Country, 
       [Column Name N] AS Continent
FROM [Table_Name]

--OR You can Simply Write without using AS Keyword
SELECT [Column Name 1] Name, 
       [Column Name 2] Country, 
       [Column Name N] Continent
FROM [Table_Name]

In MySQL, AS Keyword is optional. It is up to you to include it or not. We are going to use the below-shown Database data to explain the ALIAS Names with example.

MySQL ALIAS Names 1

MySQL Alias Example 1

In this MySQL example, we are going to rename one column name to make it more meaningful. For this, we are going to rename Name to ‘Country Name.’

USE world;
SELECT Name AS 'Country Name', 
       Continent, Region,
       SurfaceArea, IndepYear, Population, LocalName
FROM country;
MySQL ALIAS Names 2

MySQL Alias Example 2

In this example, we are using the MySQL CONCAT string function to concat or combine the Name, and region. Next, we assigned the name as Country Name using the alias column concept.

USE world;
SELECT CONCAT(Name, ' in ', Region) AS 'Country Name', 
       Continent,
       IndepYear, Population,
       SurfaceArea, LocalName 
FROM country;
MySQL ALIAS Names 4

ALIAS Columns Example 3

We can also apply or assign the Alias names to calculated columns. In this example, we will show you how to attach the Alias names to calculated columns.

USE world;
SELECT Name AS 'Country Name', 
       Continent, Region,
       IndepYear,
       2017 - IndepYear AS 'No Of Years', 
       Population,
       Population + 15000 AS 'New Population'
FROM country;

We subtracted the Independent Year from 2017, and also added 15000 to each record of the Population column. Next, we renamed them as No of Years and New Population using this Alias name.

MySQL ALIAS Names 3

MySQL Alias Command Prompt Example

In this example, we will write a SELECT query in the Command prompt to demonstrate the Alias Columns along with the Where clause.

USE world;
SELECT Name AS 'Country Name', 
       LocalName AS 'Local Name'
FROM country
WHERE Continent = 'Asia'
MySQL ALIAS Names 5

Placed Under: MySQL

  • How to Download MySQL
  • Install MySQL on Windows
  • MySQL Create Database
  • MySQL Delete Database
  • MySQL Create Table
  • MySQL Drop Table
  • MySQL SELECT Statement
  • MySQL ALIAS Column
  • MySQL Distinct
  • MySQL Insert Statement
  • MySQL Delete
  • MySQL Truncate Table
  • MySQL WHERE Clause
  • MySQL Order By
  • MySQL Group By
  • MySQL Having Clause
  • MySQL LIMIT
  • MySQL Arithmetic Operators
  • MySQL COALESCE Function
  • MySQL AND Operator
  • MySQL NOT Operator
  • MySQL OR Operator
  • MySQL XOR Operator
  • MySQL BETWEEN Operator
  • MySQL Not Between Operator
  • MySQL GREATEST Function
  • MYSQL LEAST Function
  • MySQL LIKE Operator
  • MySQL NOT LIKE Operator
  • MySQL IFNULL Operator
  • MySQL NULLIF Operator
  • MySQL INTERVAL Operator
  • MySQL IS Operator
  • MySQL IN Operator
  • MySQL NOT IN Operator
  • MySQL IS NOT NULL
  • MySQL IS NULL
  • MySQL Inner Join
  • MySQL Cross Join
  • MySQL Right Join
  • MySQL Left Join
  • MySQL Aggregate Functions
  • MySQL Date Functions
  • MySQL Date Function
  • MySQL String Functions
  • MySQL Numeric Functions
  • C Tutorial
  • C# Tutorial
  • Java Tutorial
  • JavaScript Tutorial
  • Python Tutorial
  • MySQL Tutorial
  • SQL Server Tutorial
  • R Tutorial
  • Power BI Tutorial
  • Tableau Tutorial
  • SSIS Tutorial
  • SSRS Tutorial
  • Informatica Tutorial
  • Talend Tutorial
  • C Programs
  • C++ Programs
  • Java Programs
  • Python Programs
  • MDX Tutorial
  • SSAS Tutorial
  • QlikView Tutorial

Copyright © 2021 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy