About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.

Slides:



Advertisements
Similar presentations
Restricting and sorting data 16 May May May Created By Pantharee Sawasdimongkol.
Advertisements

1Eyad Alshareef Enhanced Guide to Oracle 10g Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data.
Copyright  Oracle Corporation, All rights reserved. 2 Restricting and Sorting Data.
Introduction to Structured Query Language (SQL)
Introduction to Oracle9i: SQL1 Basic SQL SELECT Statements.
Restricting and Sorting Data. Consider the table employee(employee_id,last_name,job_id, department_id ) assume that you want to display all the employees.
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
Structured Query Language Part I Chapter Three CIS 218.
Introduction to Structured Query Language (SQL)
Concepts of Database Management Sixth Edition
A Guide to SQL, Seventh Edition. Objectives Retrieve data from a database using SQL commands Use compound conditions Use computed columns Use the SQL.
Microsoft Access 2010 Chapter 7 Using SQL.
WRITING BASIC SQL SELECT STATEMENTS Lecture 7 1. Outlines  SQL SELECT statement  Capabilities of SELECT statements  Basic SELECT statement  Selecting.
CORE 2: Information systems and Databases STORAGE & RETRIEVAL 2 : SEARCHING, SELECTING & SORTING.
Logical Operators Operator AND OR NOT Meaning Returns TRUE if both component conditions are TRUE Returns TRUE if either component condition is TRUE Returns.
Ceng 356-Lab2. Objectives After completing this lesson, you should be able to do the following: Limit the rows that are retrieved by a query Sort the.
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
IFS Intro. to Data Management Chapter 6 Filtering your data.
Chapter 2 Basic SQL SELECT Statements
 The WHERE clause, also called the predicate, provides the power to narrow down the scope of the data retrieved.  Comparison Operators Comparison OperatorDefinition.
Relational DBs and SQL Designing Your Web Database (Ch. 8) → Creating and Working with a MySQL Database (Ch. 9, 10) 1.
Chapter 2 Basic SQL SELECT Statements Oracle 10g: SQL.
15 Structured Query Language (SQL). 2 Objectives After completing this section, you should be able to: Understand Structured Query Language (SQL) and.
Chapter 3 Single-Table Queries
Microsoft Access 2010 Building and Using Queries.
Chapter 9 Joining Data from Multiple Tables
Restricting and Sorting Data. ◦ Limiting rows with:  The WHERE clause  The comparison conditions using =,
2 Copyright © Oracle Corporation, All rights reserved. Restricting and Sorting Data.
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
4 Copyright © 2006, Oracle. All rights reserved. Restricting and Sorting Data.
LECTURE 8.  Consider the table employee(employee_id,last_name,job_id, department_id )  assume that you want to display all the employees in department.
Dr. Chen, Oracle Database System (Oracle) 1 HW Discussion Chapter 5 (#9) –Why need two “deletes”? SQL> --9. SQL> SQL> DELETE FROM orderitems 2 WHERE order#
1 Single Table Queries. 2 Objectives  SELECT, WHERE  AND / OR / NOT conditions  Computed columns  LIKE, IN, BETWEEN operators  ORDER BY, GROUP BY,
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
Using Special Operators (LIKE and IN)
Concepts of Database Management Seventh Edition
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Concepts of Database Management Eighth Edition Chapter 3 The Relational Model 2: SQL.
2 第二讲 Restricting and Sorting Data. Objectives After completing this lesson, you should be able to do the following: Limit the rows retrieved by a query.
Copyright © 2004, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement Satrio Agung Wicaksono, S.Kom., M.Kom.
Copyright © 2004, Oracle. All rights reserved. Lecture 4: 1-Retrieving Data Using the SQL SELECT Statement 2-Restricting and Sorting Data Lecture 4: 1-Retrieving.
1 Querying a Single Table Structured Query Language (SQL) - Part II.
Queries SELECT [DISTINCT] FROM ( { }| ),... [WHERE ] [GROUP BY [HAVING ]] [ORDER BY [ ],...]
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
I-1 Copyright س Oracle Corporation, All rights reserved. Data Retrieval.
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
Welcome to CIS 2002: DATABASE DESIGN AND IMPLEMENTATION Semester 1, 2014 – LECTURE 2 7 January
Session 9 Accessing Data from a Database. RDBMS and Data Management/ Session 9/2 of 34 Session Objectives Describe the SELECT statement, its syntax and.
Copyright س Oracle Corporation, All rights reserved. I Introduction.
2 Copyright © 2009, Oracle. All rights reserved. Restricting and Sorting Data.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
1 Chapter 2 Basic SQL SELECT Statements. 2 Chapter Objectives Distinguish between an RDBMS and an ORDBMS Identify keywords, mandatory clauses, and optional.
1 Chapter 3 Single Table Queries. 2 Simple Queries Query - a question represented in a way that the DBMS can understand Basic format SELECT-FROM Optional.
Copyright  Oracle Corporation, All rights reserved. 2 Restricting and Sorting Data.
9/29/2005From Introduction to Oracle:SQL and PL/SQL, Oracle 1 Restricting and Sorting Data Kroenke, Chapter Two.
Limiting Selected Rows. 2-2 Objectives Sort row output using the ORDER BY clause. Sort row output using the ORDER BY clause. Enter search criteria using.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
1 ORACLE I 3 – SQL 1 Salim Phone: YM: talim_bansal.
Restricting and Sorting Data
CHAPTER 7 DATABASE ACCESS THROUGH WEB
Chapter 5 Introduction to SQL.
Writing Basic SQL SELECT Statements
Chapter 12 Subqueries and MERGE Oracle 10g: SQL
Basic select statement
ATS Application Programming: Java Programming
Restricting and Sorting Data
Restricting and Sorting Data
Shelly Cashman: Microsoft Access 2016
Restricting and Sorting Data
MySQL SQL for MySQL (I) Salim Mail :
Presentation transcript:

About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning of each presentation. You may customize the presentations to fit your class needs. Some figures from the chapters are included. A complete set of images from the book can be found on the Instructor Resources disc.

Oracle 11g: SQL Chapter 8 Restricting Rows and Sorting Data

Objectives Use a WHERE clause to restrict the rows returned by a query Create a search condition using mathematical comparison operators Use the BETWEEN…AND comparison operator to identify records within a range of values Specify a list of values for a search condition using the IN comparison operator Oracle 11g: SQL3

Objectives (continued) Search for patterns using the LIKE comparison operator Identify the purpose of the % and _ wildcard characters Join multiple search conditions using the appropriate logical operator Perform searches for NULL values Specify the order for the presentation of query results using an ORDER BY clause Oracle 11g: SQL4

WHERE Clause Syntax A WHERE clause is used to retrieve rows based on a stated condition Requires: –Column name –Comparison operator –Value or column for comparison Values are case sensitive Oracle 11g: SQL5

WHERE Clause Example List WHERE clause after FROM clause Enclose nonnumeric data in single quotes Oracle 11g: SQL6

Comparison Operators Indicate how the data should relate to the given search value Oracle 11g: SQL7

Arithmetic Comparison Operators Oracle 11g: SQL8

Other Comparison Operators Oracle 11g: SQL9

BETWEEN…AND Operator Finds values in a specified range Oracle 11g: SQL10

IN Operator Returns records that match a value in a specified list List must be in parentheses Values are separated by commas Oracle 11g: SQL11

IN Operator Example Oracle 11g: SQL12

LIKE Operator Performs pattern searches Used with wildcard characters –Underscore (_) for exactly one character in the indicated position –Percent sign (%) represents any number of characters Oracle 11g: SQL13

LIKE Operator Example Oracle 11g: SQL14

Logical Operators Used to combine conditions Evaluated in order of NOT, AND, OR –NOT – reverses meaning –AND – both conditions must be TRUE –OR – at least one condition must be TRUE Oracle 11g: SQL15

AND Logical Operator Example Oracle 11g: SQL16

OR Logical Operator Example Oracle 11g: SQL17

Multiple Logical Operators Resolved in order of NOT, AND, OR Oracle 11g: SQL18

Multiple Logical Operators Use parentheses to override the order of evaluation Oracle 11g: SQL19

Resolving Multiple Types of Operators 1.Arithmetic operators 2.Comparison operators 3.Logical operators Oracle 11g: SQL20

Treatment of NULL Values Absence of data Requires use of IS NULL operator Oracle 11g: SQL21

Treatment of NULL Values (continued) A common error is using = NULL, which does not raise an Oracle error but also does not return any rows Oracle 11g: SQL22

ORDER BY Clause Syntax The ORDER BY clause presents data in sorted order Ascending order is default Use DESC keyword to override column default 255 columns maximum Oracle 11g: SQL23

ORDER BY Clause Syntax Sort Sequence In ascending order, values will be listed in the following sequence: –Numeric values –Character values –NULL values In descending order, sequence is reversed Oracle 11g: SQL24

ORDER BY Example Oracle 11g: SQL25

ORDER BY Can Reference Column Position Oracle 11g: SQL26

Summary The WHERE clause can be included in a SELECT statement to restrict the rows returned by a query to only those meeting a specified condition When searching a nonnumeric field, the search values must be enclosed in single quotation marks Comparison operators are used to indicate how the record should relate to the search value The BETWEEN...AND comparison operator is used to search for records that fall within a certain range of values Oracle 11g: SQL27

Summary (continued) The LIKE comparison operator is used with the percent and underscore symbols (% and _) to establish search patterns Logical operators such as AND and OR can be used to combine several search conditions When using the AND operator, all conditions must be TRUE for a record to be returned in the results –However, with the OR operator, only one condition must be TRUE A NULL value is the absence of data, not a field with a blank space entered Oracle 11g: SQL28

Summary (continued) Use the IS NULL comparison operator to match NULL values; the IS NOT NULL comparison operator finds records that do not contain NULL values in the indicated column You can sort the results of queries by using an ORDER BY clause; when used, the ORDER BY clause should be listed last in the SELECT statement By default, records are sorted in ascending order; entering DESC directly after the column name sorts the records in descending order A column does not have to be listed in the SELECT clause to serve as a basis for sorting Oracle 11g: SQL29