ALIAS
ALIAS
Alias means giving a duplicate name to the column and table. Alias
is used in SELECT statement i.e there is no changes in actual table
only the changes made in display .
- Alias is two types:
1)Column Alias
2)Table Alias
Column Alias: A duplicate name given to Column name.
Syntax: SELECT <COL_NAME> AS <ALIAS_NAME> FROM
<TABLE_NAME>;
Eg: SELECT PHNO AS PHONE_NO FROM EMPLOYEE;
PHONE_NO
132247
656765
443658
980985
Table Alias: A duplicate name given to table
name.
Syntax: SELECT
<T1_COL1>,<T1_COL2>……,<T2_COL1>,<T2_COL2>
FROM <T1> AS <TABLE1>,<T2> AS <TABLE2>;
Table1 : STUDENT
ROLL NAME MARK ADDRESS DEPARTMENT
CODE
1 PUJA 45 CTC C001
2 AMRITA 40 BBSR C002
3 KALYANI 38 PURI C001
4 RUPA 43 PARADEEP C002
Table2 : DEPARTMENT
DEPARTMENT DEPARTMENT
CODE NAME
C001 IT
C002 BIOLOGY
OPERATORS IN MYSQL
An operator is a symbol that tells the compiler or interpreter to
perform specific operation. These operators are used in SELECT
statement .
There are different types of operator in MySQL :
1)Arithmetic operator :
Syntax: SELECT <EXPRESSION1> ARITHEMATIC OPERATOR
<EXPRESSION2> FROM <TABLE_NAME>
WHERE <CONDITION>;
Eg: Display roll , name & percentage of the student where total mark
is 50 .
Mysql>SELECT ROLL , NAME , MARK * 2 AS PERCENTAGE
FROM STUDENT
WHERE ROLL=1;
2)Comparison operator :
Used to compare between two value. If both are equal then returns 0,
otherwise return 1.
SYNTAX: SELECT <COL_NAME> FROM <TABLE_NAME>
WHERE <EXPRESSION> COMPARISION
OPERATOR<EXPRESSION>;
Eg: SELECT * FROM STUDENT
WHERE MARK == 45;
3)Relational operator:
SYNTAX: SELECT <COL_NAME> FROM <TABLE_NAME>
WHERE <EXPRESSION> RELATIONAL OPERATOR
<VALUE> ;
Eg: SELECT * FROM STUDENT
WHERE MARK >40 ;
Table1 : STUDENT
ROLL NAME MARK ADDRESS DEPARTMENT
CODE
1 PUJA 45 CTC C001
2 RUPA 43 PARADEEP C002
4) Logical operator :
It compares between two expression and gives true or false value. It is
also called as BOOLEAN Operator.
SYNTAX: SELECT <COL_NAME> FROM <TABLE_NAME>
WHERE <EXPRESSION> BOOLEAN OPERATOR
<EXPRESSION>;
Eg: SELECT * FROM STUDENT
WHERE MARK>= 40 AND MARK<=45;
Table1 : STUDENT
ROLL NAME MARK ADDRESS DEPARTMENT
CODE
1 PUJA 45 CTC C001
2 AMRITA 40 BBSR C002
4 RUPA 43 PARADEEP C002
6)IN Operator :This operator checks the value within a given list of
values and retrieve the matching rows in the output.
Syntax: SELECT <COL_NAME> FROM <TABLE_NAME>
WHERE <COL_NAME> IN ( VALUE1 , VALUE2 ,
………, VALUE N);
Eg: SELECT * FROM STUDENT
WHERE NAME IN (‘AARATI’ , ‘AMRITA’ , ‘PUJA’);
OPERATOR PRECEDENCE
MYSQL processes expressions according to specific operator
precedence. When an expression in an SQL statement is processed, it
is evaluated according to the order in which elements are included in
the statement.
-Precedence is the order in which the operators are evaluated in an
expression.