WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

SQL Aliases


SQL pseudonyms are utilized to incidentally rename a table or a section heading.


SQL Aliases

SQL pseudonyms are utilized to give a database table, or a segment in a table, a impermanent name.

Basically pseudonyms are made to make segment names more readable.

SQL Alias Syntax for Columns

SELECT column_name AS alias_name
FROM table_name;

SQL Alias Syntax for Tables

SELECT column_name(s)
FROM table_name AS alias_name;

Database

In this instructional exercise we will utilize the example database.

Below is a determination from the "Clients" table:

CustomerID PersonName Phone Email adderss User Pass
2 Barbara W. Messerly 405-289-4169 RobertCBray@jourrapide.com Brishemed ou6eeseeRei
3 Billy P. Losada 804-567-0813 BillyPLosada@armyspy.com Dited1976 evahNgaiz1
4 Edna M. Hymel 618-966-9060 EdnaMHymel@armyspy.com Procke Oojo7is4ei

And a determination from the "Occupation" table:

JobID CustomerID personID Dateof birth workerID
501 15 2 1982-10-16 3
502 10 5 1992-12-19 1
503 16 7 1986-03-11 2

Alias Example for Table Columns

The following SQL proclamation indicates two pseudonyms, one for the CustomerName segment and one for the ContactName column.

Example

SELECT CustomerName AS Customer, PersonName AS [Phone]
FROM Customers;

In the accompanying SQL proclamation we join four sections (Email Adderss, User, Pass) and make a nom de plume named "Address":

Example

SELECT CustomerName, Address+', '+Email Adderss+', '+User+', '+Pass AS Address
FROM Customers;
SELECT CustomerName, CONCAT(Address,', ',Email Adderssy,', ',User,', ',Pass) AS Address
FROM Customers;

Alias Example for Tables

The following SQL proclamation chooses every one of the requests from the client with CustomerID=4 (Around the Horn). We utilize the "Clients" and "Requests" tables, and give them the table assumed names of "c" and "o" individually (Here we have utilized assumed names to make the SQL shorter):

Example

SELECT o.OrderID, o.OrderDate, c.CustomerName
FROM Customers AS c, Orders AS o
WHERE c.CustomerName="Around the Horn" AND c.CustomerID=o.CustomerID;

Aliases can be helpful when:

  • There are more than one table engaged with a query
  • Functions are utilized in the query
  • Column names are enormous or not very readable
  • Two or more sections are joined together