In SQL ALIAS are temporary name of the table or column. Some time when we get the output for example when we calculate the value like using SUM function or use GROUP BY Claus then our column heading are not simple and understandable then we use ALIAS. ALIAS Set the Column heading understandable and organize our output.
For example if we have a table payments
Table -Payments
customer_name | city | Payment |
Tauqeer | Karachi | 50000 |
Zia | Lahore | 20000 |
Noman | Karachi | 30000 |
Tauqeer | Karachi | 10000 |
Noman | Karachi | 15000 |
Zia | Lahore | 30000 |
SELECT customer_name, SUM(payment) AS "Total" FROM payments
GROUP BY customer-name ;
This Total is ALIAS which display as column heading.
customer_name | Total |
Tauqeer | 60000 |
Zia | 50000 |
Noman | 45000 |
We can also use table ALIAS which are the temporary name of the table and provide alternative simple name of completed name of the tables. for example in the following statement we use select statement which get the record form two table one table is customer_information and other is customer_payments.
SELECT customer_information.ID , customer_information.Name , customer_information.Address , customer_payments.Date , customer_payments.Amount FROM customer_information , customer_payments where customer_information.ID=customer_payments.ID ;
So look this completed statement in which basically table name or taking to much spaces. So we can make easy using Table ALIAS which temporary set the short table name. For example:
SELECT A.ID, A.Name , A.Address , B.Date , B.Amount FROM customer_information A , customer_payments B where A.ID=B.ID ;
Where A and B are two Table ALIAS . Table ALIAS are defined after the table Real name in the statement . So this make simple and understandable.
Select Command
Distinct clause with Select Command
Where clause In SQL
Logical Operator in SQL SELECT Statement
IN Operator in SQL
BETWEEN Operator in SQL
Use of Wildcards in SQL
LIKE Operator in SQL
ORDER BY Clause in SQL
GROUP BY Clause in SQL
HAVING Clause in SQL
ALIAS In SQL
AS Keyword In SQL
INSERT INTO Command In SQL
Inserting Record In to a Table Form an other Table In SQL
UPDATE Command in SQL
DELETE Command in SQL
AVG Function in SQL