E Computer Notes - Restricting and Sorting Data
E Computer Notes - Restricting and Sorting Data
Objectives
After completing this lesson, you should be able to do the following:
Limit the rows retrieved by a query Sort the rows retrieved by a query
.
http://ecomputernotes.com
http://ecomputernotes.com
Character values are case sensitive, and date The default date format is DD-MON-RR.
SELECT last_name, job_id, department_id FROM employees WHERE last_name = 'Whalen';
http://ecomputernotes.com
Comparison Conditions
Operator = > >= < <= <> Meaning Equal to Greater than Greater than or equal to Less than Less than or equal to Not equal to
.
http://ecomputernotes.com
http://ecomputernotes.com
Meaning Between two values (inclusive), Match any of a list of values Match a character pattern Is a null value
.
http://ecomputernotes.com
.
http://ecomputernotes.com
http://ecomputernotes.com
SELECT
FROM WHERE
.
http://ecomputernotes.com
http://ecomputernotes.com
http://ecomputernotes.com
Logical Conditions
Operator
AND OR
Meaning Returns TRUE if both component conditions are true Returns TRUE if either component condition is true Returns TRUE if the following condition is false
NOT
http://ecomputernotes.com
http://ecomputernotes.com
http://ecomputernotes.com
Rules of Precedence
Order Evaluated 1 2 3 4 5 6 7 8 Operator Arithmetic operators Concatenation operator Comparison conditions IS [NOT] NULL, LIKE, [NOT] IN [NOT] BETWEEN NOT logical condition AND logical condition OR logical condition
.
http://ecomputernotes.com
Rules of Precedence
SELECT last_name, job_id, salary FROM employees WHERE job_id = 'SA_REP' OR job_id = 'AD_PRES' AND salary > 15000;
http://ecomputernotes.com
Rules of Precedence
Use parentheses to force priority.
SELECT last_name, job_id, salary FROM employees WHERE (job_id = 'SA_REP' OR job_id = 'AD_PRES') AND salary > 15000;
http://ecomputernotes.com
ORDER BY Clause
statement.
http://ecomputernotes.com
http://ecomputernotes.com
http://ecomputernotes.com