DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-1 David M. Kroenke’s Chapter Two: Introduction to Structured Query.

Slides:



Advertisements
Similar presentations
Database Queries and Structured Query Language (SQL) J.G. Zheng May 16 th 2008.
Advertisements

Fundamentals, Design, and Implementation, 9/e COS 346 Day 11.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 1-1 COS 346 Day 2.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 3-1 COS 346 Day5.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-1 David M. Kroenke’s Chapter Two: Introduction to Structured Query.
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 9 Structured Query Language.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 4-1 David M. Kroenke Database Processing Chapter 4 Database Design Using.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 4-1 COS 346 Day6.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 1-1 COS 346 Day 2.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-1 David M. Kroenke’s Chapter Two: Introduction to Structured Query.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 1-1 COS 346 Day 2.
Fundamentals, Design, and Implementation, 9/e Chapter 6 Introduction to Structured Query Language (SQL)
Structured Query Language Chapter Three (Excerpts) DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
Structured Query Language Chapter Three DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 6 th Edition.
Structured Query Language Chapter Three DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
David M. Kroenke and David J. Auer Database Processing: Fundamentals, Design and Implementation Chapter Two: Introduction to Structured Query Language.
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.
Structured Query Language
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-1 David M. Kroenke’s Chapter Seven: SQL for Database Construction and.
Structured Query Language Chapter Three DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 5 th Edition.
1 IT420: Database Management and Organization SQL - Data Manipulation Language 27 January 2006 Adina Crăiniceanu
Chapter 3 Single-Table Queries
Structured Query Language Chapter Three DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 4 th Edition.
MySQL By Scott Halvorson WDTC/DPG ATEC Forecasters Conference Boulder Colorado 25 July 2006.
SQL – Structured Query Language CIS 324 – Chapter 5.
David M. Kroenke and David J. Auer Database Processing: Fundamentals, Design, and Implementation Chapter Two: Introduction to Structured Query Language.
Fundamentals, Design, and Implementation, 9/e CPE 481 Database Processing Chapter 6 Structured Query Language (SQL) Instructor:Suthep Madarasmi, Ph.D.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
1 Single Table Queries. 2 Objectives  SELECT, WHERE  AND / OR / NOT conditions  Computed columns  LIKE, IN, BETWEEN operators  ORDER BY, GROUP BY,
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 11-1 David M. Kroenke’s Chapter Eleven: Managing Databases with SQL Server.
Using Special Operators (LIKE and IN)
Concepts of Database Management Seventh Edition
Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 6/1 Copyright © 2004 Please……. No Food Or Drink in the class.
Chapter 9 Structured Query Language David M. Kroenke Database Processing © 2000 Prentice Hall.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
Database Management COP4540, SCS, FIU Structured Query Language (Chapter 8)
SQL “Structured Query Language; standard language for relational data manipulation” DB2, SQL/DS, Oracle, INGRES, SYBASE, SQL Server, dBase/Win, Paradox,
Copyright © Curt Hill Queries in SQL More options.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall, modified by Dr. Lyn Mathis 4-1 David M. Kroenke’s Chapter Four: Database.
1 IT420: Database Management and Organization SQL part 3 7 February 2006 Adina Crăiniceanu
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
SqlExam1Review.ppt EXAM - 1. SQL stands for -- Structured Query Language Putting a manual database on a computer ensures? Data is more current Data is.
Structured Query Language
Database Queries aka SQL (pronounced “ sequel ” ).
David M. Kroenke and David J. Auer Database Processing Fundamentals, Design, and Implementation Chapter Four: Database Design Using Normalization 4-1 KROENKE.
DAVID M. KROENKE’S DATABASE PROCESSING, 11th Edition © 2010 Pearson Prentice Hall 2-1 David M. Kroenke’s Chapter Two: Introduction to Structured Query.
© 2002 by Prentice Hall 1 Structured Query Language David M. Kroenke Database Concepts 1e Chapter 3 3.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
David M. Kroenke and David J. Auer Database Processing: Fundamentals, Design, and Implementation Chapter Two: Introduction to Structured Query Language.
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.
9/29/2005From Introduction to Oracle:SQL and PL/SQL, Oracle 1 Restricting and Sorting Data Kroenke, Chapter Two.
David M. Kroenke and David J. Auer Database Processing Fundamentals, Design, and Implementation Chapter Four: Database Design Using Normalization.
Structured Query Language SQL-II IST 210 Organization of Data IST2101.
1 Structured Query Language (SQL) Pertemuan 09 Matakuliah: F0712 / Lab MS Access Tahun: 2007.
David M. Kroenke and David J. Auer Database Processing: Fundamentals, Design, and Implementation Chapter Ten: Managing Databases with SQL Server 2012,
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
CSIS 115 Database Design and Applications for Business Dr. Meg Fryling “Dr. Meg” Fall #csis115 © 2012 Meg Fryling.
COS 346 Day 3 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
CSIS 115 Database Design and Applications for Business
CSIS 115 Database Design and Applications for Business
COS 346 Day 3 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
Teknologji Informative
David M. Kroenke and David J
Database Principles Constructed by Hanh Pham based on slides from: “Database Processing, Fundamentals, Design, and Implementation”, D. Kroenke, D. Auer,
Access: SQL Participation Project
Database Processing: David M. Kroenke’s Chapter Five:
Presentation transcript:

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-1 David M. Kroenke’s Chapter Two: Introduction to Structured Query Language Part Two Database Processing: Fundamentals, Design, and Implementation

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-2 Using MS Access

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-3 Using MS Access (Continued)

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-4 Using MS Access (Continued)

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-5 Using MS Access - Results

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-6 Using MS SQL Server [SQL Query Analyzer]

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-7 Using Oracle [SQL*Plus]

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-8 Using Oracle [Quest Software’s TOAD]Quest Software’s TOAD

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-9 Using MySQL [MySQL Command Line Client]

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-10 Using MySQL [MySQL Query Browser]MySQL Query Browser

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-11 Sorting the Results: ORDER BY SELECT* FROMORDER_ITEM ORDER BYOrderNumber, Price;

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-12 Sort Order: Ascending and Descending SELECT* FROMORDER_ITEM ORDER BYPrice DESC, OrderNumber ASC; NOTE: The default sort order is ASC – does not have to be specified.

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-13 WHERE Clause Options: AND SELECT* FROMSKU_DATA WHEREDepartment = 'Water Sports' ANDBuyer = 'Nancy Meyers';

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-14 WHERE Clause Options: OR SELECT* FROMSKU_DATA WHEREDepartment = 'Camping' ORDepartment = 'Climbing';

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-15 WHERE Clause Options:- IN SELECT* FROMSKU_DATA WHEREBuyer IN ('Nancy Meyers', 'Cindy Lo', 'Jerry Martin');

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-16 WHERE Clause Options: NOT IN SELECT* FROMSKU_DATA WHEREBuyer NOT IN ('Nancy Meyers', 'Cindy Lo', 'Jerry Martin');

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-17 WHERE Clause Options: Ranges with BETWEEN SELECT* FROMORDER_ITEM WHEREExtendedPrice BETWEEN 100 AND 200;

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-18 WHERE Clause Options: Ranges with Math Symbols SELECT* FROMORDER_ITEM WHEREExtendedPrice >= 100 AND ExtendedPrice <= 200;

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-19 WHERE Clause Options: LIKE and Wildcards The SQL keyword LIKE can be combined with wildcard symbols: –SQL 92 Standard (SQL Server, Oracle, etc.): _ = Exactly one character % = Any set of one or more characters –MS Access (based on MS DOS) ? = Exactly one character * = Any set of one or more characters

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-20 WHERE Clause Options: LIKE and Wildcards (Continued) SELECT* FROMSKU_DATA WHEREBuyer LIKE 'Pete%';

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-21 WHERE Clause Options: LIKE and Wildcards (Continued) SELECT* FROMSKU_DATA WHERESKU_Description LIKE '%Tent%';

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-22 WHERE Clause Options: LIKE and Wildcards SELECT* FROMSKU_DATA WHERESKU LIKE '%2__';

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-23 SQL Built-in Functions There are five SQL Built-in Functions: –COUNT –SUM –AVG –MIN –MAX

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-24 SQL Built-in Functions (Continued) SELECTSUM (ExtendedPrice) ASOrder3000Sum FROMORDER_ITEM WHEREOrderNumber = 3000;

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-25 SQL Built-in Functions (Continued) SELECTSUM (ExtendedPrice) AS OrderItemSum, AVG (ExtendedPrice) AS OrderItemAvg, MIN (ExtendedPrice) AS OrderItemMin, MAX (ExtendedPrice) AS OrderItemMax FROMORDER_ITEM;

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-26 SQL Built-in Functions (Continued) SELECTCOUNT(*) AS NumRows FROMORDER_ITEM;

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-27 SQL Built-in Functions (Continued) SELECTCOUNT (DISTINCT Department) AS DeptCount FROMSKU_DATA;

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-28 Arithmetic in SELECT Statements SELECTQuantity * Price AS EP, ExtendedPrice FROMORDER_ITEM;

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-29 String Functions in SELECT Statements SELECTDISTINCT RTRIM (Buyer) + ' in ' + RTRIM (Department) AS Sponsor FROMSKU_DATA;

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-30 The SQL keyword GROUP BY SELECTDepartment, Buyer, COUNT(*) AS Dept_Buyer_SKU_Count FROMSKU_DATA GROUP BY Department, Buyer;

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-31 The SQL keyword GROUP BY (Continued) In general, place WHERE before GROUP BY. Some DBMS products do not require that placement, but to be safe, always put WHERE before GROUP BY. The HAVING operator restricts the groups that are presented in the result. There is an ambiguity in statements that include both WHERE and HAVING clauses. The results can vary, so to eliminate this ambiguity SQL always applies WHERE before HAVING.

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-32 The SQL keyword GROUP BY (Continued) SELECTDepartment, COUNT(*) AS Dept_SKU_Count FROMSKU_DATA WHERESKU <> GROUP BY Department ORDER BY Dept_SKU_Count;

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-33 The SQL keyword GROUP BY (Continued) SELECTDepartment, COUNT(*) AS Dept_SKU_Count FROMSKU_DATA WHERESKU <> GROUP BY Department HAVING COUNT (*) > 1 ORDER BYDept_SKU_Count;

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-34 Querying Multiple Tables: Subqueries SELECTSUM (ExtendedPrice) AS Revenue FROMORDER_ITEM WHERESKU IN (SELECTSKU FROMSKU_DATA WHERE Department = 'Water Sports'); Note: The second SELECT statement is a subquery.

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-35 Querying Multiple Tables: Subqueries (Continued) SELECTBuyer FROMSKU_DATA WHERESKU IN (SELECTSKU FROMORDER_ITEM WHEREOrderNumber IN (SELECTOrderNumber FROMRETAIL_ORDER WHEREOrderMonth = 'January' ANDOrderYear = 2004));

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-36 Querying Multiple Tables: Joins SELECTBuyer, ExtendedPrice FROMSKU_DATA, ORDER_ITEM WHERESKU_DATA.SKU = ORDER_ITEM.SKU;

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-37 Querying Multiple Tables: Joins (Continued) SELECTBuyer, SUM(ExtendedPrice) AS BuyerRevenue FROMSKU_DATA, ORDER_ITEM WHERESKU_DATA.SKU = ORDER_ITEM.SKU GROUP BYBuyer ORDER BYBuyerRevenue DESC;

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-38 Querying Multiple Tables: Joins (Continued) SELECTBuyer, ExtendedPrice, OrderMonth FROMSKU_DATA, ORDER_ITEM, RETAIL_ORDER WHERESKU_DATA.SKU = ORDER_ITEM.SKU ANDORDER_ITEM.OrderNumber = RETAIL_ORDER.OrderNumber;

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-39 Subqueries versus Joins Subqueries and joins both process multiple tables. A subquery can only be used to retrieve data from the top table. A join can be used to obtain data from any number of tables, including the “top table” of the subquery. In Chapter 7, we will study the correlated subquery. That kind of subquery can do work that is not possible with joins.

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-40 David M. Kroenke’s Database Processing Fundamentals, Design, and Implementation (10 th Edition) End of Presentation: Chapter Two Part Two