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

SQL Tutorial (Chap10)

sql basics

Uploaded by

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

SQL Tutorial (Chap10)

sql basics

Uploaded by

jaggu011
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

 Chapter 10: Relational Operators

 SQL Tutorial - Equals to (=) Operator

Relational Operator Equals to:


= [Equalsto]

This operator is used for equality test. Used to test the equality of two operands.

Example:-
Display the details of Employees whose salary is equal to 2000.

SQL> SELECT *FROM emp WHERE sal=2000;

SQL Tutorial - Lessthan (<) Operator

Relational Operator Lessthan:


This operator is used for less than test. Example a<b checks that operand ‘a’ is less than ‘b’ or not.

Example: Display the details of the employees whose salary is less than 3000.
SQL> SELECT * FROM emp WHERE sal < 3000

Here if you observe we got a result values whose salary is less than the operand 3000.
SQL Tutorial - Greaterthan (>) Operator

Relational Operator Greater than:


(Greater than Operator) >
This operator is used for Greater than test. For example a>b checks the operand ‘a’ is greater
than ‘b’ or not.

Example:
Display the details of Employees whose salary is greater than 3000
SQL> SELECT * FROM emp WHERE sal > 3000;

SQL Tutorial - Less than or Equals to


(<=) Operator

Relational Operator Less than or Equals to:


Lessthan or Equals to Operator (<=)
This operator is used for Less than or Equal to test. For example a<=b, here checks whether
operand ‘a’ is less than or equals to operand ‘b’. If a<b then condition is true and if a=b then also
condition is true but if a>b then condition is false.

Example :
Display the details of Employees whose salary is less than or equal to 3000.
SQL> SELECT * FROM EMP WHERE sal <= 3000;
SQL Tutorial - Greater than or Equals to
(>=) Operator

Relational Operator Greater than or Equals to:


Greater than or Equals to (>=)
This operator is used to check the Greater than or equal test. For example a>=b checks the operand
‘a’ is greater than operand ‘b’ or operand ‘a’ is equals to the operand ‘b’.

Example:
Display the details of Employees whose salary is greater than or equal to 3000.

SQL> SELECT * FROM emp WHERE sal >= 3000;

Not Equals to ( != / ^= / <> ) Operator

Relational Operator Not Equals to:


Not equals to ( != or ^= or <> )
This operator is used for inequality test.

Examples:
Display the details of employees whose salary is not equals to 2000.
SELECT * FROM emp WHERE sal != 2000;

SELECT * FROM emp WHERE sal ^= 2000;

SELECT * FROM emp WHERE sal <> 2000;


SQL IN Operator

IN :
 Returns true if value is available in given list of values
 Supports with all types of data (data types)

In the below example only employees whose empno is (7125,7369,7782) are fetched.
SQL> SELECT *FROM emp WHERE empno IN (7125, 7369, 7782);

Inside DML statements:


SQL> UPDATE emp SET sal=sal+200 WHERE ename IN (‘SMITH’,’ALLEN’,’WARD’);

SQL> DELETE FROM emp WHERE hiredate IN (‘22-DEC-82’,’ 17-NOV-81’);

SQL BETWEEN Operator


BETWEEN

 Returns true if value specified is within the specified range.


 Supports with numbers and date values.
 between is an inclusive operator which includes range limits in output
Example:- in this example all employee records are fetched whose salary is between 2000 and
3000
SQL> SELECT *FROM emp WHERE sal BETWEEN 2000 AND 3000;

Whenever lower bound value is larger than upper bound then it shows ‘no rows selected’
Example:-
SQL> SELECT *FROM emp WHERE sal BETWEEN 3000 AND 2000;

Output:

-- No rows selected

SQL LIKE Operator

LIKE:-

 Used to search for pattern in a given input


 It is supported with character data only
 It uses two Meta characters

% (percentage) and _ (underscore) are two Meta characters.


% (percentage) represents “zero or more characters “in the given input
_ (underscore) represents “one character” in given input.
Example:- Display the employees whose name is starting with ‘S’ in EMP table.

SQL> SELECT * FROM emp WHERE ename LIKE ‘S%’;

Display the employees whose name ends with ‘S’ in EMP table
SQL> SELECT * FROM emp WHERE ename LIKE ‘%S’;

Display the employees whose names are having second letter as ‘L’ in EMP table
SQL> SELECT * FROM emp WHERE ename LIKE ‘_L%’;

SQL IS NULL Operator

IS NULL:-
 Used to search for NULL values In the given input
 Supports with all types of data

Example:-
SQL> SELECT * FROM emp WHERE sal IS NULL;

Output:-

-- No rows selected;

AS there IS salary available FOR every employee.

Let’s fetch all employees whose has commission enabled.


SQL> SELECT *FROM emp WHERE comm IS NULL;

SQL Concatenation ( || ) Operator


Character operators or Concatenation Operators are used in expressions to
manipulate character strings.
Look at the below example it shows how to use the Character Operator.
SQL>SELECT 'The Name of the employee is: ' || ENAME FROM EMP;
Output:

You might also like