Welcome to plsql4all.blogspot.com SQL, MYSQL, ORACLE, TERADATA, MONGODB, MARIADB, GREENPLUM, DB2, POSTGRESQL.

Saturday, 6 September 2014

ALIASES in MySQL

We can have temporary name to a COLUMN or TABLE. This is called alias to column or table.

Synatx:-

SELECT EMPNAME AS EMP_NAME, EMPNO AS EMP_NO FROM EMPLOYEE;



SELECT EMPNAME AS EMP_NAME, EMPNO AS EMP_NO FROM EMPLOYEE;

EMP_NAME                 EMP_NO
-------------------- ----------
CHANCHAL                      1
WANKHADE                      2



Above EMP_NAME and EMP_NO are temporary names to the column. It is also called as column "ALIAS".

Now let's see how to alias tables:-

SELECT EMPNAME EMP_NAME, EMPNO EMP_NO,D.DEPTNO DEPT_NO
FROM EMPLOYEE AS E INNER JOIN DEPARTMENT AS D
ON E.DEPTNO=D.DEPTNO;



SELECT EMPNAME EMP_NAME, EMPNO EMP_NO,D.DEPTNO DEPT_NO
FROM EMPLOYEE AS E INNER JOIN DEPARTMENT AS D
ON E.DEPTNO=D.DEPTNO;

EMP_NAME                 EMP_NO    DEPT_NO
-------------------- ---------- ----------
CHANCHAL                      1         10
WANKHADE                      2         20

Above E and D are the temporary names for the employee and department table which are also called as table "ALIAS".




Also Read:-  ALIAS in MairaDB

No comments:

Post a Comment

Please provide your feedback in the comments section above. Please don't forget to follow.