Friday, 31 January 2020

Operators and Keywords in SQL


1.Read the data with ‘Order by’

select * from Employee order by EmpAge;

By default, it sorts the value in ascending order or we can use:

 select * from Employee order by EmpAge;

For sorting the value in descending order:

select * from Employee order by EmpAge DESC;

When we give the query like below it first gives the priority to EmpAge then to EmpID:

select * from Employee order by EmpAge, EmpID;

2.Read the data using the ‘AND’ Operator

select * from Employee where EmpID>2 and EmpAge<30;

3.Read the data using the ‘OR’ Operator

select * from Employee where EmpID>2 AND EmpAge<30;
select * from Employee where Empname='Johny' and (Empage=25 or EmpPhNum=989866)

4.Read the data using the ‘NOT’ keyword

select * from Employee where not EmpAge>30;
select * from Employee where EmpPhNum='989866' and not Empage=25

5.Read the data using the LIKE keyword

Query for the data starts with John:
select * from Employee where EmpName Like 'John%';

Query for the data ends with son:
select * from Employee where EmpName Like '%son';

Query for the data have ‘oh’ in the middle:
select * from Employee where EmpName Like '%oh%';

Query for the data ends with ‘n’ and another one character. Here _ represent a character
select * from Employee where EmpName Like '%n_';

Query for the data start with ‘J’ and ends with ‘n’.
select * from Employee where EmpName Like 'J%n'

6.Read the data using ‘NULL’ keywords

select * from Employee where EmpPhNum is NULL
select * from Employee where EmpPhNum is NOT NULL

No comments:

Post a Comment