0% found this document useful (0 votes)
6 views6 pages

SQL Data Selection and Filtering Guide

Uploaded by

aruntyzon
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views6 pages

SQL Data Selection and Filtering Guide

Uploaded by

aruntyzon
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1) SELECTION:

The process of retrieving data by selecting both rows and columns is


known as selection.
i. Col-name Operator Col-name
ii. Col-name Operator Values

Where Clause:
It is used to filter the records. It executes row by row. For the
where clause we can pass filter condition as an argument(inputs), if the
condition is satisfied it returns true (or) if the condition fails to satisfy it
returns false, we call it as Boolean Value.
We can pass multiple arguments to the where clause with the help
of logical operators.
Filter conditions are of two formats:
i. Col-name Operator Col-name
ii. Col-name Operator Values Literals

Literals:
Literals are also known as values (or) Operands. Literals are
classified into three types Number Literal, Character Literal and Date
literal.
Character literal and Date literal are case sensitive and should be
written within single quotes (' ').
Note: SQL is case insensitive language, where-as literals are case
sensitive.
Syntax:
Select Col-name/ Expression
From Table-name
Where <Filter-condition>; optional
Eg:
1. WAQTD Name of employee working in Dept 20?
a. Select Ename From emp where deptno=20;
2. WAQTD Ename, Sal and Hiredate for all emps whose earnings are
more than 2000?
a. Select Ename, Sal, Hiredate From emp Where sal>2000;
3. WAQTD Details of Smith?
a. Select * from emp where ename = ‘SMITH’;
4. WAQTD all the details of employee along with annual salary
whose EID is 7902?
a. Select emp.*, sal*12 from emp where empno=7902;
5. WAQTD of the employee who hiredate before 01- JAN – 87?
a. Select * from emp where hiredate < ’01-JAN-87’;
6. WAQTD Ename, Designation for all emps who is working as
manager?
a. Select ename, job from emp where job=’MANAGER’;
7. WAQTD Name, salary and hiredate for all emps who hired before
85?
a. Select ename, sal, hiredate from emp where hiredate <
‘01- JAN – 85’ ;
8. WAQTD Ename, hiredate if emps are hired after 85?
a. Select ename, hiredate from emp where hiredate > ’31-
DEC-85’ (or) where hiredate >=’01-JAN-86’;

ASSIGNMENT -3:
1. WAQTD the annual salary of emp whose name is smith?
2. WAQTD name of emps working as clerk?
3. WAQTD salary of the emps who are working as salesman?
4. WAQTD details of emp who earns more than 2000?
5. WAQTD details of emp whose name is Jones?
6. WAQTD name and sal along with his annual salary if the annual
salary is more than 1200?
7. WAQTD empno of the emps who are working in dept 30?
8. WAQTD name and salary given to an employee if emps earns a
commission of rupees 1400?
9. WAQTD Details of emps having commission more than salary?
10. WAQTD empno of emps hired before the year 87?
OPERATORS:
1. Arithmetic Operators (+, -, *, /)
2. Comparison Operators (=, !=, (< >))
3. Relational Operators (<, >, <=, >=)
4. Concatenation Operators (||)
5. Logical Operators (AND, OR, NOT)
6. Special Operators (IN, NOT IN, BETWEEN, NOT BETWEEN,
LIKE, NOT LIKE, IS, IS NOT)
7. Sub query Operators (ALL, ANY, EXISTS, NOT EXISTS)

Concatenation Operators:
It is used to join the multiple string. To join N number of string we should
always use (n-1) times the operator.
Eg: ‘Hi’ || ‘Dingi’  ‘Hi Dingi’
Select ‘Hi’ || Ename from emp;
 Select ‘Hi’ || ‘Dingi’ from emp; Ans: Hi Dingi
 ‘Hi’ || Ename || ‘Your sal is ’ || sal Ans: Hi
Smith Your sal is 800

Logical Operators:
It is used to write multiple condition. We have three logical operators are
AND, OR and NOT.
a) AND :
AND operator works as logical multiplication. It returns true if both the
conditions are satisified. If the 1st condition fails to satisfy, there is no need for
checking 2nd condition because the result will be always false.
We use AND operator whenever we need to satisfy both the conditions.
C1 C2 RESULT
F F F
F T F
T
b)OR:
T F F
T
T T T OR operator works as logical addition. It returns true
if any one of the condition is satisfied. If the 1st condition is satisfied, there is no
need for checking 2nd condition because the result will be always true.
We use OR operator whenever we need to satisfy any one of the
condition.

a) NOT(Negotation / Inversor):
NOT operator works as Inversor. It returns true if the condition is false
and returns false if the condition true. We use NOT operator whenever
we want to inverse the result.
C RESULT
T F
F T

Eg:
1. WAQTD details of emp who is working as manager in dept 10?
a. Select * from emp where job=’manager’ and deptno=10;
2. WAQTD Ename, sal, hiredate for all emps who are working in dept=20
and getting salary more than 1000?
a. Select ename,sal,hiredate from emp where deptno=20 and
sal>1000;
3. WAQTD all the details of the emp who are working as manager (or)
earning more than 2000?
a. Select * from emp where job=’manager’ (or) sal >2000;
4. WAQTD all details of emp along with annual salary for all the emps who
are earning more than 3000 as a president?
a. Select emp.*,sal*12 from emp where job=’president’ and
sal>3000;
5. WAQTD details of emp along with annual salary if emp is working in
dept 10 with annual salary more than 20000?
a. Select emp.*, sal*12 annual_sal from emp where deptno=10 and
sal*12 >20000;
6. WAQTD details of emp who is working as manager and earning salary
more than 2000 but less than 4000?
a. Select * from emp where job=’manager’ and sal>2000 and
sal<4000;
7. WAQTD details of emp who is working in dept 20 and hired before 85?
a. Select * from emp where deptno=20 and hiredate <’01-JAN-85’;
8. WAQTD all details of emp who are working in dept 10 and 20?
a. Select * from emp where deptno=10 or deptno=20;
9. WAQTD details of emp who are working as clerk, manager, analyst?
a. Select * from emp where job=’clerk’ or job=’manager’ or
job=’analyst’;
10. WAQTD details of emp who are working as clerk (or) manager in dept
10?
a. Select * from emp where deptno=10 and (job=’clerk’ or
job=’manager’);
(or)
Select * from emp where (job=’clerk’ or job=’manager’) and
deptno=10;
Note: Whenever we use AND operator and OR operator together, always the 1st
priority will be given to AND operator.

ASSIGNMENT - 4:
1. WAQTD details of emps working as clerk and earning less than 1500?
2. WAQTD name and hiredate of emps working as manager in dept 30?
3. WAQTD details of emp along with annual salary if they are working in
dept 30 as salesman and their annual salary has to be greater than 14000?
4. WAQTD names of emps whose salary is less than 1100 and their
designation is clerk?
5. WAQTD name and sal, annual sal and deptno if deptno is 20 earning
more than 1100 and their designation is clerk?
6. WAQTD name and sal, annual sal and deptno if deptno is 20 earning
more than 1100 and annual salary exceeds 12000?
7. WAQTD empno and names of emps working as manager in dept 20?
8. WAQTD details of emps working in dept 20 or 30?
9. WAQTD details of emps working as analyst in dept 10?
10. WAQTD details of emp working as president with salary of rupees 4000?
11. WAQTD names of emps hired after 81 into dept 10 or 30?
12. WAQTD all details along with annual salary if sal is BETWEEN 1000
and 4000 annual salary more than 15000?

You might also like