Restricting Data and Sorting Data PDF
Restricting Data and Sorting Data PDF
Database Design
Muhammad Rudyanto Arief
rudy@amikom.ac.id
Objectives
After completing this lesson, you should be able to do the
following :
– Limit the rows that are retrieved by a query
– Sort the rows that are retrieved by a query
Limiting Rows Using a Selection
EMPLOYEES
SELECT first_name
FROM employees
WHERE first_name LIKE ‘S%’;
Using the LIKE Condition
You can combine pattern-matching characters.
You can use the ESCAPE identifier to search for the actual % and _
symbols.
SELECT last_name
FROM employees
WHERElast_name LIKE ‘_o%’;
Using the NULL Conditions
Test for nulls with the IS NULL operator.
Operator Meaning
NOT Returns TRUE if both component
conditions are true
AND Returns TRUE if either component
condition is true
OR Returns TRUE if the following condition
is false
Using the AND Operator
AND requires both conditions to be true:
2
FROM employees
WHERE (job_id = ‘SA_REP’
OR job_id = ‘AD_PRES’)
AND salary > 15000;
Using the ORDER BY Clause
Sort retrieved rows with the ORDER BY clause:
ASC: ascending order, default
DESC: descending order
The ORDER BY clause comes last in the SELECT statement:
SELECT last_name, job_id, department_id, hire_date
FROM employees
ORDER BY hire_date;
Sorting
Sorting in descending order:
SELECT last_name, job_id, department_id, hire_date
FROM employees
ORDER BY hire_date DESC ; 1