Presentation is loading. Please wait.

Presentation is loading. Please wait.

 The WHERE clause, also called the predicate, provides the power to narrow down the scope of the data retrieved.  Comparison Operators Comparison OperatorDefinition.

Similar presentations


Presentation on theme: " The WHERE clause, also called the predicate, provides the power to narrow down the scope of the data retrieved.  Comparison Operators Comparison OperatorDefinition."— Presentation transcript:

1

2  The WHERE clause, also called the predicate, provides the power to narrow down the scope of the data retrieved.  Comparison Operators Comparison OperatorDefinition =Equal !=,<>Not equal >,>=Greater than, greater than or equal to <,<=Less than, less than or equal to BETWEEN…And..Inclusive of two values LIKEPattern matching with wildcard characters % and _ IN(…)List of values IS NULLTest for null values

3  Equality, denoted by = Select first_name, last_name, phone from instructor where last_name = ‘Schorin’;  Inequality, denoted by !=  Data types must be the same.

4  >, =,<= Select description, cost from course where cost >= 1195;

5  Tests for a range of values. Select description, cost from course where cost between 1000 and 1100;

6  Works with a list of value, separated by commas, contained within a set of parentheses. Select description, cost from course where cost in (1095, 1595);

7  Performs pattern matching using wild cards % and _ Select first_name, last_name, phone from instructor where last_name like ‘%S%’; Select first_name, last_name, phone from instructor where last_name like ‘_o%’;

8  All previously mentioned operators can be negated with the NOT comparison operator. Select phone from instructor where last_name not like ‘%S%’;

9  Is Null and Is Not Null determines whether there is an unknown value in the data. Select description, prerequisite from course where prerequisite Is Null;

10  Comparison operators can be combined with the help of the logical operators AND and OR Select description, cost from course where cost = 1095 or cost = 1195 and description LIKE ‘I%’;  AND always takes precedence over OR, but precedence can be changed with parentheses. Select description, cost from course where (cost = 1095 or cost = 1195) and description like ‘I%’;

11  SQL uses tri-value logic; this means a condition can evaluate to true, false, or unknown(null);  Null values cannot be compared so they cannot be returned for queries using non-null values with comparison operators.

12 TRUEFALSEUNKNOWN TRUE FALSEUNKNOWN FALSE UNKNOWN FALSEUNKNOWN OR TRUTH TABLE TRUEFALSEUNKNOWN TRUE FALSETRUEFALSEUNKNOWN TRUEUNKNOWN

13 TRUEFALSEUNKNOWN NOTFALSETRUEUNKNOWN

14  Go to page 111 in book  Answer and discuss answers in class.

15  Data is not stored in any particular order  Result sets are displayed in whatever order they are returned from the database  The ORDER BY clause to is used to order data any way you wish.  You can use ASC or DESC and the sequence number of the column instead of the name. Select course_no, description from course where prerequisite is NULL ORDER BY DESCRIPTION.

16  If the SELECT list contains DISTINCT, the column(s)the keyword pertains to must also be listed in the ORDER BY clause. SELECT distinct first_name, last_name from student where zip =‘10025’ order by first_name, last_name;

17  The default sort order is to have nulls listed last.  This can be changed by using NULLS FIRST or NULLS LAST in the ORDER BY clause. Select DISTINCT cost from course order by cost nulls first;

18  Double-click one of the columns in the column header to sort.  You can also use the SQL Developer Data tab, which allows you to retrieve data from a table without writing a SQL statement.  Sort and filters can be done using this tab.

19  A column alias can be used in the SELECT list to give a column or an expression an alias.  You can order by an alias name. Select first_name first, first_name “First Name”, first_name as “First” From student Where zip = ‘10025’;

20  Placing comments or remarks in a SQL statement is very useful for documenting purpose, thought, and ideas.  Very handy for when you have developed multiple statements saved in a script.  You must identify a comment with either a – or /* */ --This is a single line comment /*This is a multi-line comment */

21  Click CTRL+S on the keyboard, the save icon, or go to File  Save to save the sql script.  To open the file, use CTRL+O, the open icon, or go to File  Open.

22  You will inevitably make mistakes. Oracle returns an error number and an error message to inform you of any mistake.  Errors can be one or many and the error message is not always indicative of the problem.  The parser works from the front of the query and works backward; therefore, the first error message will be for the first error the parser encounters.  You can look up the Oracle error message in the Oracle Database Error Messages manual at Oracle.com or refer to Appendix G and Appendix H.

23  Go to page 127 in book  Answer and discuss answers in class.

24  Quiz will be given at the beginning of our next class


Download ppt " The WHERE clause, also called the predicate, provides the power to narrow down the scope of the data retrieved.  Comparison Operators Comparison OperatorDefinition."

Similar presentations


Ads by Google