0% found this document useful (0 votes)
2 views

ALIAS

The document explains the concept of aliases in SQL, detailing both column and table aliases, along with their syntax and examples. It also covers various types of operators in MySQL, including arithmetic, comparison, relational, logical, BETWEEN AND, IN, and LIKE operators, providing syntax and examples for each. Additionally, it mentions operator precedence in MySQL, which determines the order of evaluation in SQL statements.

Uploaded by

m acharya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

ALIAS

The document explains the concept of aliases in SQL, detailing both column and table aliases, along with their syntax and examples. It also covers various types of operators in MySQL, including arithmetic, comparison, relational, logical, BETWEEN AND, IN, and LIKE operators, providing syntax and examples for each. Additionally, it mentions operator precedence in MySQL, which determines the order of evaluation in SQL statements.

Uploaded by

m acharya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

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

Eg: SELECT S.ROLL AS ROLL, S.NAME, S.MARK,


D.DEPARTMENTNAME FROM STUDENT AS S ,
DEPARTMENT AS D
WHERE S.DEPARTMENTCODE =D.DEPARTMENTCODE;
S.ROLL S.NAME S.MARK D.DEPARTMENTNAME
1 PUJA 45 IT
2 AMRITA 40 BIOLOGY
3 KALYANI 38 IT
4 RUPA 43 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;

ROLL NAME PERCENTAG


E
1 PUJA 90

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;

ROLL NAME MARK ADDRESS DEPARTMENT


CODE
1 PUJA 45 CTC C001

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

5)BETWEEN AND operator :


This operator is used to show a range of values of the specified
column , including the lower and upper values.
SYNTAX: SELECT<COL_NAME> FROM <TABLE_NAME>
WHERE <COL_NAME> BETWEEN <VALUE1> AND
<VALUE2>;
Eg: SELECT * FROM SUUDENT
WHERE MARK BETWEEN 40 AND 45;

ROLL NAME MARK ADDRESS DEPARTMENT


CODE
1 PUJA 45 CTC C001
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’);

ROLL NAME MARK ADDRESS DEPARTMENT


CODE
1 PUJA 45 CTC C001
2 AMRITA 40 BBSR C002

7)LIKE Operator :This operator is used to search data ,which does


not match exactly with the criteria. The LIKE operator is used along
with wildcard characters to fetch records, where the data matches the
specified patterns.
The wildcard characters used in MySQL are ,
(i) Percentage sign(%) used to match any sequence of
characters.
(ii) Underscore (_) used to match single character.
The symbols can also be used combinations.
Syntax: SELECT <COL_NAME> FROM <TABLE_NAME>
WHERE <COL_NAME> LIKE <PATTERN>;
Eg: Display the student record whose name starts with ‘R’
MySQL>SELECT * FROM STUDENT
WHERE NAME LIKE ‘R%’;
ROLL NAME MARK ADDRESS DEPARTMENT
CODE
2 RUPA 43 PARADEEP C002

Eg: MySQL>SELECT * FROM STUDENT


WHERE NAME LIKE ‘_U %’;
ROLL NAME MARK ADDRESS DEPARTMENT
CODE
1 PUJA 45 CTC C001
4 RUPA 43 PARADEEP C002

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.

You might also like