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 1-1 COS 346 Day 2.
Fundamentals, Design, and Implementation, 9/e Chapter 6 Introduction to Structured Query Language (SQL)
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-1 David M. Kroenke’s Chapter Two: Introduction to Structured Query.
Structured Query Language Part I Chapter Three CIS 218.
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.
Chapter 3 Single-Table Queries
Structured Query Language Chapter Three DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 4 th Edition.
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.
SQL “Structured Query Language; standard language for relational data manipulation” DB2, SQL/DS, Oracle, INGRES, SYBASE, SQL Server, dBase/Win, Paradox,
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
DATA RETRIEVAL WITH SQL Goal: To issue a database query using the SELECT command.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
(C) 2000, The University of Michigan 1 Database Application Design Handout #5 February 4, 2000.
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.
Simple Queries DBS301 – Week 1. Objectives Basic SELECT statement Computed columns Aliases Concatenation operator Use of DISTINCT to eliminate duplicates.
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.
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
SQL FUNDAMENTALS CDSE Days 2018.
David M. Kroenke and David J
Database Processing: David M. Kroenke’s Chapter One: Introduction
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 (Ctd)

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

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 MySQL [MySQL Command Line Client]

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

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

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 SUM SELECTSUM (ExtendedPrice) ASOrder3000Sum FROMORDER_ITEM WHEREOrderNumber = 3000;

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-25 Multiple Built-in Functions 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 COUNT SELECTCOUNT(*) AS NumRows FROMORDER_ITEM;

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

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

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

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-30 GROUP BY SELECTDepartment, COUNT(*)AS Dept_SKU_Count FROMSKU_DATA GROUP BY Department; DepartmentDept_SKU_Count Camping2 Climbing2 Water Sports4

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-31 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-32 GROUP BY and ORDER BY 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 HAVING SELECTDepartment, COUNT(*) AS Dept_SKU_Count FROMSKU_DATA WHERESKU <> GROUP BY Department HAVING COUNT (*) > 1;

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 Nested Subqueries 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 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 Joins 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 Two Joins 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.

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