Comparison Condition:-
Comparison conditions are used in conditions that compare one expression to another value or expression. These operator are used in WHERE condition.
Comparison Operator:-
1. Equal to (=):-
SELECT *
FROM EMPLOYEES
WHERE EMPLOYEE_ID = 100;
2. GREATER THAN (>):-
SELECT *
FROM EMPLOYEES
WHERE SALARY > 4000;
3. LESS THAN (<):-
SELECT *
FROM EMPLOYEES
WHERE SALARY < 5000;
4. GREATER THAT OR EQUAL TO (>=)
SELECT *
FROM EMPLOYEES
WHERE SALARY >= 4000;
5. LESS THAN OR EQUAL TO (<=):-
SELECT *
FROM EMPLOYEES
WHERE SALARY <= 5000;
6. NOT EQUAL TO (<>):-
SELECT *
FROM EMPLOYEES
WHERE DEPARTMENT_ID <> 50;
Others Comparison Operator:-
1. BETWEEN .. AND ..:- Between two value(include)
SELECT *
FROM EMPLOYEES
WHERE DEPARTMENT_ID BETWEEN (200 AND 300);
2. IN:- Match any of the list of values
SELECT *
FROM EMPLOYEES
WHERE EMPLOYEE_ID IN(101, 110, 200, 220, 109);
3. LIKE:- Match a character pattern.
SELECT *
FROM EMPLOYEES
WHERE LAST_NAME LIKE '%A%';
4. IS NULL:- Is a null value.
SELECT *
FROM EMPLOYEES
WHERE COMMISSION_PCT IS NULL;
Logical Condition:-
1. AND:- If both compare condition are TRUE then it return TRUE.
SELECT *
FROM EMPLOYEES
WHERE SALARY < 20000
AND DEPARTMENT_ID = 20;
2. OR:- If any one compare condition is TRUE then it return TRUE.
SELECT *
FROM EMPLOYEES
WHERE SALARY < 20000
OR DEPARTMENT_ID = 20;
3. NOT:- If condition is false then it return TRUE.
SELECT *
FROM EMPLOYEES
WHERE DEPARTMENT_ID NOT IN(10,50);
No comments:
Post a Comment