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#

Slides:



Advertisements
Similar presentations
Dr. Chen, Oracle Database System (Oracle) 1 Chapter 12 Subqueries and Merge Statements (up to p.451) Jason C. H. Chen, Ph.D. Professor of MIS School of.
Advertisements

Chapter 11 Group Functions (up to p.402)
Introduction to Structured Query Language (SQL)
Introduction to Structured Query Language (SQL)
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
Introduction to Structured Query Language (SQL)
Concepts of Database Management Sixth Edition
Microsoft Access 2010 Chapter 7 Using SQL.
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.
Dr. Chen, Business Database Systems (Oracle) Chapter 2 Connecting to Oracle 11g and Basic SQL SELECT Statements Jason C.H. Chen, Ph.D. Professor of MIS.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Chapter 2 Basic SQL SELECT Statements
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
ASP.NET Programming with C# and SQL Server First Edition
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.
Chapter 3 Single-Table Queries
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Dr. Chen, Oracle Database System (Oracle) 1 Database Development DDL DML DCL JL_D.B. ORACLE (SQL Components) (Retrieve Data and Produce Information from.
Dr. Chen, Oracle Database System (Oracle) 1 Chapter 4 Constraints Jason C. H. Chen, Ph.D. Professor of MIS School of Business Gonzaga University Spokane,
Chapter 5 Data Manipulation and Transaction Control
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
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.
Dr. Chen, Oracle Database System (Oracle) 1 Chapter 6 Additional Database Objects (up to p.195 and all in the pptx file) Jason C. H. Chen, Ph.D. Professor.
Dr. Chen, Business Database Systems (Oracle) Instruction on Creating sql files and SPOOL Jason C.H. Chen, Ph.D. Professor of MIS School of Business, Gonzaga.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
1 Single Table Queries. 2 Objectives  SELECT, WHERE  AND / OR / NOT conditions  Computed columns  LIKE, IN, BETWEEN operators  ORDER BY, GROUP BY,
SQL (DDL & DML Commands)
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
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Concepts of Database Management Eighth Edition Chapter 3 The Relational Model 2: SQL.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
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.
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
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 3 Single Table Queries. 2 Simple Queries Query - a question represented in a way that the DBMS can understand Basic format SELECT-FROM Optional.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
9/29/2005From Introduction to Oracle:SQL and PL/SQL, Oracle 1 Restricting and Sorting Data Kroenke, Chapter Two.
Simple Queries DBS301 – Week 1. Objectives Basic SELECT statement Computed columns Aliases Concatenation operator Use of DISTINCT to eliminate duplicates.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
Tarik Booker CS 122. What we will cover… Tables (review) SELECT statement DISTINCT, Calculated Columns FROM Single tables (for now…) WHERE Date clauses,
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
Dr. Chen, Oracle Database System (Oracle) 1 Basic Nested Queries and Views Jason C. H. Chen, Ph.D. Professor of MIS School of Business Gonzaga University.
Restricting and Sorting Data
CHAPTER 7 DATABASE ACCESS THROUGH WEB
Chapter 5 Introduction to SQL.
Writing Basic SQL SELECT Statements
 2012 Pearson Education, Inc. All rights reserved.
Basic select statement
CS122 Using Relational Databases and SQL
Basic Nested Queries and Views
Restricting and Sorting Data
Restricting and Sorting Data
Shelly Cashman: Microsoft Access 2016
Restricting and Sorting Data
Presentation transcript:

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# = 1005; 1 row deleted. SQL> SQL> DELETE FROM orders 2 WHERE order# = 1005; 1 row deleted. Order#Customer#OrderDateShipDateShipStreetShipCityShipStateShipZipShipCost NUMBER(4) DATE VARCHAR2(18)VARCHAR2(15)VARCHAR2(2)NUMBER(4)NUMBER(4,2) Order#Item#ISBNQuantityPaidEach NUMBER(4)NUMBER(2)VARCHAR2(10)NUMBER(3)NUMBER(5,2) ORDERS pk ORDERITEMS fk cpk

Dr. Chen, Oracle Database System (Oracle) 2 Database Development DDL DML DCL JL_D.B. ORACLE (SQL Components) (Retrieve Data and Produce Information)

Dr. Chen, Oracle Database System (Oracle) 3 Chapter 8 Restricting Rows and Sorting Data (from a Single Table) Jason C. H. Chen, Ph.D. Professor of MIS School of Business Gonzaga University Spokane, WA USA

Dr. Chen, Oracle Database System (Oracle) 4 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

Dr. Chen, Oracle Database System (Oracle) 5 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 Extra GROUP BY and HAVING examples are also introduced.

Dr. Chen, Oracle Database System (Oracle) 6 Refresh the Database Run the following script file –Start c:\oradata\chapter8\JLDB_Build_8.sql Note that we will first study “Logical Operator” follows by “Comparison Operator”.

Dr. Chen, Oracle Database System (Oracle) 7 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 (within ‘…’) Figure 8-1 Syntax of the SELECT statement SELECT [DISTINCT | UNIQUE] (*, field-1 [As alias], field-2, …) FROM tablename [WHERE condition] [GROUP BY group_by_expression] [HAVING group_condition] [ORDER BY columname];

Dr. Chen, Oracle Database System (Oracle) 8 MORE ON SELECT Figure 8-1 Syntax of the SELECT statement SELECT [DISTINCT | UNIQUE] (*, field-1 [As alias], field-2, …) FROM tablename-1, tablename-2, … [WHERE condition] [GROUP BY group_by_expression] [HAVING group_condition] [ORDER BY columname]; SELECT [DISTINCT | UNIQUE] (*, field-1 [As alias], field-2, …) FROM tablename [WHERE condition] [GROUP BY group_by_expression] [HAVING group_condition] [ORDER BY columname]; What is the difference between these two ‘SELECT” Single Table Multiple Tables

Dr. Chen, Oracle Database System (Oracle) 9 WHERE Clause Example List WHERE clause after FROM clause Enclose nonnumeric data in single quotes Figure 8-3 Results of a state-based search

Dr. Chen, Oracle Database System (Oracle) 10 Rules for Character Strings -- chapter 8, Figure 8-4; p.247 SELECT * FROM customers WHERE customer# = 1010; -- chapter 8, Figure 8-5; p.247 SELECT * FROM books WHERE isbn = ; --****************************** -- chapter 8, Figure 8-5(b); p.247 SELECT * FROM books WHERE isbn = ' '; -- chapter 8, Figure 8-6; p.248 SELECT * FROM books WHERE pubdate = '21-JAN-05';

Dr. Chen, Oracle Database System (Oracle) 11 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

Dr. Chen, Oracle Database System (Oracle) 12 AND Logical Operator Example Figure 8-24 Searching with multiple conditions and the AND logical operator

Dr. Chen, Oracle Database System (Oracle) 13 OR Logical Operator Example Figure 8-25 Searching with multiple conditions and the OR logical operator

Dr. Chen, Oracle Database System (Oracle) 14 Multiple Logical Operators Resolved in order of NOT, AND, OR Figure 8-26 Searching with both AND and OR operators (NOT A GOOD WAY – why? See next example)

Dr. Chen, Oracle Database System (Oracle) 15 Multiple Logical Operators Use parentheses to override the order of evaluation Figure 8-27 Using parentheses to control the evaluation order for logical operators

Dr. Chen, Oracle Database System (Oracle) 16 Resolving Multiple Types of Operators 1.Arithmetic operators 2.Comparison operators 3.Logical operators

Dr. Chen, Oracle Database System (Oracle) 17 Comparison Operators Indicate how the data should relate to the given search value Figure 8-7 Searching for books with a retail price greater than $55 -- chapter 8, Figure 8-8; p.250 SELECT title FROM books WHERE title > 'HO';

Dr. Chen, Oracle Database System (Oracle) 18 Arithmetic Comparison Operators Table 8-2 Comparison Operators

Dr. Chen, Oracle Database System (Oracle) 19 Other Comparison Operators Table 8-2 Comparison Operators (cont.)

Dr. Chen, Oracle Database System (Oracle) 20 Practice … Figure 8-9 to Figure 8-13 (pp ) -- chapter 8, Figure 8-9; p.251 SELECT title, retail-cost profit FROM books WHERE retail-cost < cost*.2; -- chapter 8, Figure 8-10; p.252 SELECT firstname, lastname, state FROM customers WHERE state <= 'GA'; -- chapter 8, Figure 8-11; p.253 SELECT firstname, lastname, state FROM customers WHERE state >= 'GA'; -- chapter 8, Figure 8-12; p.254 SELECT firstname, lastname, state FROM customers WHERE state <> 'GA'; -- chapter 8, Figure 8-13; p.255 SELECT order#, orderdate FROM orders WHERE orderdate < '01-APR-09'; What is the interpretation on this SQL command?

Dr. Chen, Oracle Database System (Oracle) 21 BETWEEN…AND Operator Finds values in a specified range Figure 8-14 Searching Pubid with the BETWEEN … AND operator

Dr. Chen, Oracle Database System (Oracle) chapter 8, Figure 8-15(c); p.256 SELECT title FROM books WHERE title BETWEEN ‘B' AND ‘H'; TITLE BODYBUILD IN 10 MINUTES A DAY BUILDING A CAR WITH TOOTHPICKS DATABASE IMPLEMENTATION COOKING WITH MUSHROOMS E-BUSINESS THE EASY WAY BIG BEAR AND LITTLE DOVE 6 rows selected. exclusive TITLE BODYBUILD IN 10 MINUTES A DAY REVENGE OF MICKEY BUILDING A CAR WITH TOOTHPICKS DATABASE IMPLEMENTATION COOKING WITH MUSHROOMS HOLY GRAIL OF ORACLE HANDCRANKED COMPUTERS E-BUSINESS THE EASY WAY PAINLESS CHILD-REARING THE WOK WAY TO COOK BIG BEAR AND LITTLE DOVE HOW TO GET FASTER PIZZA HOW TO MANAGE THE MANAGER SHORTEST POEMS What is the output? How many records? inclusive -- chapter 8, Figure 8-15; p.256 SELECT title FROM books SELECT title FROM books WHERE title >= ‘B' AND title <=‘H';

Dr. Chen, Oracle Database System (Oracle) chapter 8, Figure 8-15(d); p.256 SELECT title FROM books WHERE title BETWEEN 'B' AND 'HO'; TITLE BODYBUILD IN 10 MINUTES A DAY BUILDING A CAR WITH TOOTHPICKS DATABASE IMPLEMENTATION COOKING WITH MUSHROOMS HANDCRANKED COMPUTERS E-BUSINESS THE EASY WAY BIG BEAR AND LITTLE DOVE 7 rows selected. TITLE BODYBUILD IN 10 MINUTES A DAY REVENGE OF MICKEY BUILDING A CAR WITH TOOTHPICKS DATABASE IMPLEMENTATION COOKING WITH MUSHROOMS HOLY GRAIL OF ORACLE HANDCRANKED COMPUTERS E-BUSINESS THE EASY WAY PAINLESS CHILD-REARING THE WOK WAY TO COOK BIG BEAR AND LITTLE DOVE HOW TO GET FASTER PIZZA HOW TO MANAGE THE MANAGER SHORTEST POEMS -- chapter 8, Figure 8-15; p.256 SELECT title FROM books SELECT title FROM books WHERE title >= 'B' AND title <='HO'; What is the output? How many records?

Dr. Chen, Oracle Database System (Oracle) 24 SELECT orderdate FROM orders WHERE orderdate BETWEEN '31-Mar-09' AND '02-Apr-09’; ORDERDATE MAR APR APR-09 inclusive SELECT * FROM EmployeeAddressTable WHERE LastName BETWEEN 'Ackerman' AND 'Scott‘; Retrieve employees alphabetically between (and including) "Ackerman" and exclusive "Scott".

Dr. Chen, Oracle Database System (Oracle) 25 IN Operator and Example Returns records that match a value in a specified list List must be in parentheses Values are separated by commas What logical operator can be used to replace IN ? More on the next slide Figure 8-16 Searching Pubid with the IN operator

Dr. Chen, Oracle Database System (Oracle) 26 Other Examples (IN, NOT IN) -- chapter 8, Figure 8-17; p.257 SELECT firstname, lastname, state FROM customers WHERE state IN ('CA', 'TX'); -- chapter 8, Figure 8-18; p.258 SELECT firstname, lastname, state FROM customers WHERE state NOT IN ('CA', 'TX'); -- chapter 8, Figure 8-17(b) an alternate way SELECT firstname, lastname, state FROM customers WHERE state = 'CA‘ state = 'TX'; OR

Dr. Chen, Oracle Database System (Oracle) 27 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 Figure 8-19 Searching with the LIKE operator and the % wildcard character

Dr. Chen, Oracle Database System (Oracle) 28 More Examples -- chapter 8, Figure 8-20; p.259 SELECT customer#, lastname, firstname FROM customers WHERE customer# LIKE '10_9'; -- chapter 8, Figure 8-21; p.260 SELECT isbn, title FROM books WHERE isbn LIKE '_4%0'; -- chapter 8, Figure 8-22; p.261 SELECT * FROM testing;

Dr. Chen, Oracle Database System (Oracle) 29 Treatment of NULL Values Absence of data Requires use of IS NULL operator Figure 8-28 Searching for NULL values with the IS NULL operator -- chapter 8, Figure 8-29; p.266 SELECT order#, shipdate FROM orders WHERE shipdate IS NOT NUL

Dr. Chen, Oracle Database System (Oracle) 30 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 Figure 8-30 Using the = NULL operator by mistake

Dr. Chen, Oracle Database System (Oracle) 31 An extra table for GROUP BY and HAVING loc_idbldg_coderoomcapacity NUMBER(6),VARCHAR2(10)VARCHAR2(6)NUMBER(5) location CREATE TABLE location (loc_id NUMBER(6), bldg_code VARCHAR2(10), room VARCHAR2(6), capacity NUMBER(5), CONSTRAINT location_loc_id_pk PRIMARY KEY (loc_id)); You need to download (create a new folder of \NW_CW\) and run the following command to make the example c:\oradata\NW_CW\northwoods.sql

Dr. Chen, Oracle Database System (Oracle) 32 GROUP BY Clauses – Extra Examples The group by clause is used to form groups of rows of a resulting table based on column clauses. When the group by clause is used, all aggregate operations are computed on the individual groups, not on the entire table. --Figure G-0 (wrong version) -- NOT a group by expression: -- ROOM SELECT bldg_code, room, SUM(capacity), AVG(capacity), MAX(capacity) FROM location WHERE capacity >= 5 GROUP BY bldg_code; --Figure G-1 -- right version of group by SELECT bldg_code, SUM(capacity), AVG(capacity), MAX(capacity) FROM location WHERE capacity >= 5 GROUP BY bldg_code; Output from Figure G-1 BLDG_CODE SUM(CAPACITY) AVG(CAPACITY) MAX(CAPACITY) BUS CR

Dr. Chen, Oracle Database System (Oracle) 33 --Figure G-1 -- the right version of group by SELECT bldg_code, SUM(capacity), AVG(capacity), MAX(capacity) FROM location WHERE capacity >= 5 GROUP BY bldg_code; --Figure G-2 -- the right version of group by w/ having SELECT bldg_code, SUM(capacity) TOTAL_CAPACITY, AVG(capacity), MAX(capacity) FROM location WHERE capacity >= 5 GROUP BY bldg_code HAVING AVG(capacity) >=42; Output from Figure G-1 BLDG_CODE SUM(CAPACITY) AVG(CAPACITY) MAX(CAPACITY) BUS CR Output from Figure G-2 BLDG_CODE TOTAL_CAPACITY AVG(CAPACITY) MAX(CAPACITY) CR The Group by and Having Clauses The having clause is used to eliminate certain groups from further consideration. The following query will produce the same results but with the AVG capacity of at least 42.

Dr. Chen, Oracle Database System (Oracle) 34 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 Figure 8-31 Syntax of the SELECT statement

Dr. Chen, Oracle Database System (Oracle) 35 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

Dr. Chen, Oracle Database System (Oracle) 36 Examples on ORDER BY Figure 8-32, 34 Sorting results by publisher name in ascending and descending orders

Dr. Chen, Oracle Database System (Oracle) 37 Figure 8-36 The default sort order for NULL valuesFigure 8-37 Using the NULL FIRST option in the ORDER BY clause

Dr. Chen, Oracle Database System (Oracle) 38 Secondary Sort Figure 8-38 Using primary and secondary sort columns In the previous examples, only one column was specified in the ORDER BY clause, which is called a primary sort. In some cases, you might want to include a secondary sort, which specifies a second filed to sort b if an exact match occurs between two or more rows in the primary sort.

Dr. Chen, Oracle Database System (Oracle) 39 ORDER BY Example Figure 8-39 Sorting on the State and City columns

Dr. Chen, Oracle Database System (Oracle) 40 ORDER BY Can Reference Column Position Figure 8-40 Referencing positions of sort columns in the ORDER BY clause

Dr. Chen, Oracle Database System (Oracle) 41 Practice all the examples in the text. A Script file is available on the Bb (file name: Ch8Queries.sql) After completing all examples, do the HW.

Dr. Chen, Oracle Database System (Oracle) 42 Homework - Hands-On Assignments Read and Practice all examples on Chapters 8 1. Run the script files (in the folder \oradata\chapter8\): JLDB_Build_8.sql 2. Read Oracle assignment and create a script file Oracle_ch8_Lname_Fname.sql for questions (all EVEN numbers; p.281) on “Hands-on Assignments”. Use appropriate COLUMN statements to produce readable outputs if needed. 3. Execute and test one problem at a time and make sure they are all running successfully. 4. When you done, spool the script files (see next slide for spooling instructions) and UPLOAD the file (Oracle_ch8_Spool_Lname_Fname.txt) to Bb by the midnight before the next class. Upload the spooled file (*.txt) to the Bb (under “Assignments & Projects”) by the deadline.

Dr. Chen, Oracle Database System (Oracle) 43 How to Spool your Script and Output Files After you tested the script file of Oracle_ch6_Lname_Fname.sql successfully, follow the instructions below to spool both script and output files: Step 0. Run the following script file from SQL*Plus (since you have created JLDB tables) –Start c:\oradata\chapter6\JLDB_Build_6.sql 1. type the following on SQL> –Spool c:\oradata\Oracle_ch6_Spool_Lname_Fname.txt (make sure your name is entered) 2. open Oracle_ch6_Lname_Fname.sql that you already tested 3. copy and paste all the SQL commands (including all comments) to the SQL*PLUS 4. type Spool Off on the SQL> The output should contain your personal information, all SQL commands and their solution on the.txt file and saved in C: drive (oradata\ folder) Upload the spooled file (*.txt) to the Bb (under “Assignments & Projects”) by the deadline.

Dr. Chen, Oracle Database System (Oracle) 44 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

Dr. Chen, Oracle Database System (Oracle) 45 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

Dr. Chen, Oracle Database System (Oracle) 46 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