Restricting and Sorting Data. Copyright 2004, Oracle. All rights reserved.

Similar documents
Restricting and Sorting Data. Copyright 2004, Oracle. All rights reserved.

Oracle Database 10g: SQL Fundamentals I

Retrieving Data Using the SQL SELECT Statement. Copyright 2004, Oracle. All rights reserved.

Retrieving Data Using the SQL SELECT Statement. Copyright 2004, Oracle. All rights reserved.

RESTRICTING AND SORTING DATA

Retrieving Data Using the SQL SELECT Statement. Copyright 2009, Oracle. All rights reserved.

Database Foundations. 6-4 Data Manipulation Language (DML) Copyright 2015, Oracle and/or its affiliates. All rights reserved.

Manipulating Data. Copyright 2004, Oracle. All rights reserved.

GIFT Department of Computing Science Data Selection and Filtering using the SELECT Statement

Limit Rows Selected. Copyright 2008, Oracle. All rights reserved.

Database Programming with SQL

Using the Set Operators. Copyright 2006, Oracle. All rights reserved.

Táblák tartalmának módosítása. Copyright 2004, Oracle. All rights reserved.

Join, Sub queries and set operators

Data Manipulation Language

Using the Set Operators. Copyright 2004, Oracle. All rights reserved.

INDEX. 1 Basic SQL Statements. 2 Restricting and Sorting Data. 3 Single Row Functions. 4 Displaying data from multiple tables

RETRIEVING DATA USING THE SQL SELECT STATEMENT

Working with Columns, Characters and Rows. Copyright 2008, Oracle. All rights reserved.

Database Programming with SQL

Retrieving Data from Multiple Tables

Using DbVisualizer Variables

Oracle Database: SQL Fundamentals I. Oracle Internal & Oracle Academy Use Only. Volume II Student Guide. D64258GC10 Edition 1.0 January 2010 D65028

Institute of Aga. Network Database LECTURER NIYAZ M. SALIH

Intermediate SQL: Aggregated Data, Joins and Set Operators

DUE: 9. Create a query that will return the average order total for all Global Fast Foods orders from January 1, 2002, to December 21, 2002.

Institute of Aga. Microsoft SQL Server LECTURER NIYAZ M. SALIH

Oracle Database SQL Basics

chapter 2 G ETTING I NFORMATION FROM A TABLE

Bsc (Hons) Software Engineering. Examinations for / Semester 1. Resit Examinations for BSE/15A/FT & BSE/16A/FT

Database Programming with SQL

Conversion Functions

Creating Other Schema Objects

Database Programming - Section 18. Instructor Guide

Database Programming with PL/SQL

Course Overview. Copyright 2010, Oracle and/or its affiliates. All rights reserved.

EXISTS NOT EXISTS WITH

What Are Group Functions? Reporting Aggregated Data Using the Group Functions. Objectives. Types of Group Functions

Getting Information from a Table

SELF TEST. List the Capabilities of SQL SELECT Statements

Oracle Database 11g: SQL Fundamentals I

Using DDL Statements to Create and Manage Tables. Copyright 2004, Oracle. All rights reserved.


Oracle 1Z Oracle Database 11g SQL Fundamentals I. Download Full Version :

Using DDL Statements to Create and Manage Tables. Copyright 2006, Oracle. All rights reserved.

CSC Web Programming. Introduction to SQL

Sun Certified MySQL Associate

Using DDL Statements to Create and Manage Tables. Copyright 2004, Oracle. All rights reserved.

MANAGING DATA(BASES) USING SQL (NON-PROCEDURAL SQL, X401.9)

Lab # 6. Data Manipulation Language (DML)

Oracle Database 10g: SQL Fundamentals I

Assignment Grading Rubric

SQL Structured Query Language Introduction

Testing Masters Technologies

ITCertMaster. Safe, simple and fast. 100% Pass guarantee! IT Certification Guaranteed, The Easy Way!

Database Programming with SQL

Full file at

Alkérdések II. Copyright 2004, Oracle. All rights reserved.

12. MS Access Tables, Relationships, and Queries

Creating Other Schema Objects. Copyright 2004, Oracle. All rights reserved.

DEFAULT Values, MERGE, and Multi-Table Inserts. Copyright 2009, Oracle. All rights reserved.

Oracle Database 10g: Introduction to SQL

30. Structured Query Language (SQL)

Implementing Table Operations Using Structured Query Language (SQL) Using Multiple Operations. SQL: Structured Query Language

HNDIT 1105 Database Management Systems

CS 275 Winter 2011 Problem Set 3

Database Programming with SQL

1Z Oracle Database 11g - SQL Fundamentals I Exam Summary Syllabus Questions

Relational Database Management Systems for Epidemiologists: SQL Part I

1 Writing Basic SQL SELECT Statements 2 Restricting and Sorting Data

Introduction to Oracle9i: SQL

Database Programming - Section 7. Instructor Guide

Database Programming with PL/SQL

Oracle Database 11g: SQL Fundamentals I COPYRIGHTED MATERIAL. PArt

Database Programming with PL/SQL

DUE: CD_NUMBER TITLE PRODUCER YEAR 97 Celebrate the Day R & B Inc Holiday Tunes for All Tunes are US 2004

Chapter 3 How to retrieve data from a single table

2) SQL includes a data definition language, a data manipulation language, and SQL/Persistent stored modules. Answer: TRUE Diff: 2 Page Ref: 36

Database Design - Section 18. Instructor Guide

School of Computing and Information Technology Session: Spring CSCI835 Database Systems (Bridging Subject) Sample class test 23 July 2018

COMP102: Introduction to Databases, 4

Introduction to Oracle9i: SQL

Database Foundations. 6-3 Data Definition Language (DDL) Copyright 2015, Oracle and/or its affiliates. All rights reserved.

In This Lecture. Yet More SQL SELECT ORDER BY. SQL SELECT Overview. ORDER BY Example. ORDER BY Example. Yet more SQL

Database Programming with SQL

Structure Query Language (SQL)

BraindumpsVCE. Best vce braindumps-exam vce pdf free download

Database Systems: Design, Implementation, and Management Tenth Edition. Chapter 7 Introduction to Structured Query Language (SQL)

Based on the following Table(s), Write down the queries as indicated: 1. Write an SQL query to insert a new row in table Dept with values: 4, Prog, MO

Test Bank for Database Processing Fundamentals Design and Implementation 13th Edition by Kroenke

Chapter 7. Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel

Introduction to Oracle9i: SQL Basics

Oracle 1Z Oracle Database 11g : SQL Fundamentals I. Download Full Version :

ÇALIŞMA TEST SORULARI

1 Organizational issues

Lab # 6. Using Subqueries and Set Operators. Eng. Alaa O Shama

Language. f SQL. Larry Rockoff COURSE TECHNOLOGY. Kingdom United States. Course Technology PTR. A part ofcenqaqe Learninq

tablename ORDER BY column ASC tablename ORDER BY column DESC sortingorder, } The WHERE and ORDER BY clauses can be combined in one

PASS4TEST. IT Certification Guaranteed, The Easy Way! We offer free update service for one year

Microsoft Access 2007 Lesson 2: Retrieving Information from a Database

Transcription:

Restricting and Sorting Data

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 Use ampersand substitution in isql*plus to restrict and sort output at run time

Limiting Rows Using a Selection EMPLOYEES retrieve all employees in department 90

Limiting the Rows That Are Selected Restrict the rows that are returned by using the WHERE clause: SELECT * {[DISTINCT] column expression [alias],...} FROM table [WHERE condition(s)]; The WHERE clause follows the FROM clause.

Using the WHERE Clause SELECT employee_id, last_name, job_id, department_id WHERE department_id = 90 ;

Character Strings and Dates Character strings and date values are enclosed by single quotation marks. Character values are case-sensitive, and date values are format-sensitive. The default date format is DD-MON-RR. SELECT last_name, job_id, department_id WHERE last_name = 'Whalen' ;

Comparison Conditions Operator <> BETWEEN...AND... IN(set) LIKE = > >= < <= IS NULL Meaning Equal to Greater than Greater than or equal to Less than Less than or equal to Not equal to Between two values (inclusive) Match any of a list of values Match a character pattern Is a null value

Using Comparison Conditions SELECT last_name, salary WHERE salary <= 3000 ;

Using the BETWEEN Condition Use the BETWEEN condition to display rows based on a range of values: SELECT last_name, salary WHERE salary BETWEEN 2500 AND 3500 ; Lower limit Upper limit

Using the IN Condition Use the IN membership condition to test for values in a list: SELECT employee_id, last_name, salary, manager_id WHERE manager_id IN (100, 101, 201) ;

Using the LIKE Condition Use the LIKE condition to perform wildcard searches of valid search string values. Search conditions can contain either literal characters or numbers: % denotes zero or many characters. _ denotes one character. SELECT first_name WHERE first_name LIKE 'S%' ;

Using the LIKE Condition You can combine pattern-matching characters: SELECT last_name WHERE last_name LIKE '_o%' ; You can use the ESCAPE identifier to search for the actual % and _ symbols.

Using the NULL Conditions Test for nulls with the IS NULL operator. SELECT last_name, manager_id WHERE manager_id IS NULL ;

Logical Conditions Operator AND OR NOT 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

Using the AND Operator AND requires both conditions to be true: SELECT employee_id, last_name, job_id, salary WHERE salary >=10000 AND job_id LIKE '%MAN%' ;

Using the OR Operator OR requires either condition to be true: SELECT employee_id, last_name, job_id, salary WHERE salary >= 10000 OR job_id LIKE '%MAN%' ;

Using the NOT Operator SELECT last_name, job_id WHERE job_id NOT IN ('IT_PROG', 'ST_CLERK', 'SA_REP') ;

Rules of Precedence Operator 1 2 3 4 5 6 7 8 9 Meaning Arithmetic operators Concatenation operator Comparison conditions IS [NOT] NULL, LIKE, [NOT] IN [NOT] BETWEEN Not equal to NOT logical condition AND logical condition OR logical condition You can use parentheses to override rules of precedence.

Rules of Precedence SELECT last_name, job_id, salary WHERE job_id = 'SA_REP' OR job_id = 'AD_PRES' AND salary > 15000; 1 SELECT last_name, job_id, salary WHERE (job_id = 'SA_REP' OR job_id = 'AD_PRES') AND salary > 15000; 2

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 ORDER BY hire_date ;

Sorting Sorting in descending order: SELECT last_name, job_id, department_id, hire_date ORDER BY hire_date DESC ; 1 Sorting by column alias: SELECT employee_id, last_name, salary*12 annsal ORDER BY annsal ; 2 Sorting by multiple columns: SELECT last_name, department_id, salary ORDER BY department_id, salary DESC; 3