Filtering Data by Using Different Operators: Syeda Rabia Kazim

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 15

Filtering Data by using different

Operators

SYEDA RABIA KAZIM


 Character strings and date values are enclosed in
single quotation marks.
 •Character values are case sensitive, and date
values are format sensitive.
Character The default date format is DD-MON-YY.
Strings and SELECT last_name, job_id, department_id

Dates FROM employees


WHERE last_name = ’Whalen’;
Other
Comparison
Conditions
SELECT column1, column2....columnN
FROM table_name

WHERE column_name BETWEEN val-1 AND val-2;


 Use the BETWEEN condition to display rows based on a
range of values.

Using the SELECT last_name, salary

BETWEEN FROM employees

Condition WHERE salary


BETWEEN 2500 AND 3500;
 The SELECT statement on the slide returns rows from the
EMPLOYEES table for any employee whose salary is between
2,500 and 3,500.
 Values specified with the BETWEEN condition are inclusive.
You must specify the lower limit first.
SELECT column1, column2....columnN
FROM table_name
WHERE column_name IN (val-1, val-2,...val-N);
 Use the IN membership condition to test for values
in a list.

Using the IN SELECT employee_id, last_name, salary, manager_id


FROM employees
Condition WHERE manager_id IN (100, 101, 201);
 The slide example displays employee numbers,
last names, salaries, and manager’s employee
numbers for all the employees whose manager’s
employee number is 100, 101, or 201.
 The IN condition can be used with any data type.
The following example returns a row from the
EMPLOYEES table for any employee whose last
name is included in the list of names in the
Using the IN WHERE clause:

Condition SELECT employee_id, manager_id, department_id


FROM employees
WHERE last_name IN (’Abel’, ’Ande’);
SELECT

column1, column2....columnN
FROM table_name
WHERE column_name LIKE { PATTERN };
Using the  Use the LIKE condition to perform wildcard searches
LIKE of valid search string values.

Condition  Search conditions can contain either literal characters


or numbers:
 The SELECT statement on the slide returns the
employee first name from the EMPLOYEES table for
any employee whose first name begins with an S.
Note the uppercase S. Names beginning with an s are
not returned.
 The LIKE condition can be used as a shortcut for some
BETWEEN comparisons.
 The following example displays the last names and
hire dates of all employees who joined between
January 1995 and December 1995:
SELECT last_name, hire_date
FROM employees
WHERE hire_date LIKE ’%95’;
LIKE Operator Description

WHERE CustomerName LIKE 'a%' Finds any values that starts with "a"

WHERE CustomerName LIKE '%a' Finds any values that ends with "a"

Like WHERE CustomerName LIKE '%or%' Finds any values that have "or" in any
position

operator- WHERE CustomerName LIKE '_r%' Finds any values that have "r" in the

wild card
second position

search
WHERE CustomerName LIKE 'a_%_%' Finds any values that starts with "a" and
are at least 3 characters in length

WHERE ContactName LIKE 'a%o' Finds any values that starts with "a" and
ends with "o"
 If a row lacks the data value for a particular
column, that value is said to be null, or to contain
a null.

Defining a  A null is a value that is unavailable, unassigned,


unknown, or inapplicable.
Null Value  Columns of any data type can contain nulls.
SELECT last_name, job_id, salary, commission_pct
FROM employees;
 Test for nulls with the IS NULL operator.
SELECT last_name, manager_id

FROM employees
WHERE manager_id IS NULL;
 The NULL conditions include the IS NULL condition and
Using the the IS NOT NULL condition

NULL  The slide example retrieves the last names and


managers of all employees who do not have a manager.
Conditions  For another example, to display last name, job ID, and
commission for all employees who are NOT entitled to
get a commission
SELECT last_name, job_id, commission_pct
FROM employees
WHERE commission_pct IS NULL;
SELECT last_name AS name, emp_id
FROM employees;

Defining a  If the alias contains spaces or special characters


Column Alias- (such as # or $), or is case sensitive, enclose the
Renames a alias in double quotation marks (" ").
column heading
SELECT last_name "Name", salary*12 "Annual
Salary" FROM employees;
 Concatenates columns or character strings to
other columns
 Is represented by two vertical bars (||)
Concatenati  Creates a resultant column that is a character

on Operator expression
SELECT last_name||job_id AS "Employees"
FROM employees;
 A literal is a character, a number, or a date included
in the SELECT list. • Date and character literal values
must be enclosed within single quotation marks.
SELECT last_name ||’ is a ’||job_id

Literal AS "Employee Details"

Character FROM employees;

Strings In the following example, the last name and salary for
each employee are concatenated with a literal to give
the returned rows more meaning
SELECT last_name ||’: 1 Month salary = ’||salary
Monthly FROM employees;
 The default display of queries is all rows, including
duplicate rows.

SELECT department_id

Duplicate FROM employees;

Rows  Eliminate duplicate rows by using the DISTINCT


keyword in the SELECT clause.
SELECT DISTINCT department_id
FROM employees;

You might also like