SQL Notes Chapter 8
SQL Notes Chapter 8
The retrieval of data from the table by selecting both columns and records is known as
Selection.
Syntax:
SELECT */[DISTINCT] COL_NAME/EXPRESSION [ALIAS]
FROM TABLE_NAME
WHERE <filter condition>;
Order of execution
1.FROM
2.WHERE – Row by row
3.SELECT – Row by row
WHERE clause is used to filter the records.
WHERE clause executes row by row.
WHERE clause executes after the execution of FROM clause.
For WHERE clause we have to pass filter condition as an argument.
For WHERE clause we can pass multiple filter conditions by using logical
operators.
Example 1:
EMPNO ENAME SAL DEPTNO
1 ALLEN 2000 20
2 BLAKE 3000 10
3 SMITH 9000 30
4 SCOTT 2000 20
5 JAMES 4000 30
6 BLAKE 3000 10
WAQTD Employee names and their dept no’s where the employees should be
working in dept no 20.
SELECT ENAME, DEPTNO
FROM EMP
WHERE DEPTNO=20;
Execution
Input 1
Output
Input 2
TRUTH TABLE
INPUT 1 INPUT 2 OUTPUT
TRUE TRUE TRUE
TRUE FALSE FALSE
FALSE TRUE FALSE
FALSE FALSE FALSE
2. OR: OR operator returns true even if any of the conditions any one of the
conditions is true. OR operator is used between the conditions.
Input 1
Output
Input 2
TRUTH TABLE
INPUT 1 INPUT 2 OUTPUT
TRUE TRUE TRUE
TRUE FALSE TRUE
FALSE TRUE TRUE
FALSE FALSE FALSE
OR operator follows Binary addition.
INPUT 1 INPUT 2 OUTPUT
0 0 0
0 1 1
1 0 1
1 1 1
3. NOT: NOT operator is used as negation. NOT operator will accept only one
input. If we pass true, it will return false Similarly if we pass false, it will return
true.
Input Output
TRUEFALSE
FALSETRUE
01
10