1 Structured Query Language (SQL) Pertemuan 09 Matakuliah: F0712 / Lab MS Access Tahun: 2007.

Slides:



Advertisements
Similar presentations
Writing Basic SQL SELECT Statements. Capabilities of SQL SELECT Statements A SELECT statement retrieves information from the database. Using a SELECT.
Advertisements

The University of Akron Dept of Business Technology Computer Information Systems The Relational Model: Query-By-Example (QBE) 2440: 180 Database Concepts.
XP Chapter 3 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Analyzing Data For Effective Decision Making.
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 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 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.
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.
Concepts of Database Management, 4th Edition, Pratt & Adamski
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.
Queries and SQL in Access Please use speaker notes for additional information!
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.
Concepts of Database Management, Fifth Edition
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
Chapter 3 Single-Table Queries
Structured Query Language Chapter Three DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 4 th Edition.
Microsoft Access 2010 Chapter 7 Using SQL. Change the font or font size for SQL queries Create SQL queries Include fields in SQL queries Include simple.
Microsoft Access 2010 Building and Using Queries.
Analyzing Data For Effective Decision Making Chapter 3.
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.
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,
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
Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 6/1 Copyright © 2004 Please……. No Food Or Drink in the class.
Ways to use SQL statements You can directly submit them to the DBMS for processing You can embed SQL statements into client/server application programs.
Concepts of Database Management Eighth Edition Chapter 3 The Relational Model 2: SQL.
STRUCTURED QUERY LANGUAGE SQL-II IST 210 Organization of Data IST210 1.
Advanced SELECT Queries CS 146. Review: Retrieving Data From a Single Table Syntax: Limitation: Retrieves "raw" data Note the default formats… SELECT.
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.
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.
Database Queries aka SQL (pronounced “ sequel ” ).
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.
Simple Queries DBS301 – Week 1. Objectives Basic SELECT statement Computed columns Aliases Concatenation operator Use of DISTINCT to eliminate duplicates.
1 SQL Chapter 9 – 8 th edition With help from Chapter 2 – 10 th edition.
Writing Basic SQL SELECT Statements Lecture
Structured Query Language SQL-II IST 210 Organization of Data IST2101.
Retrieving Information Pertemuan 3 Matakuliah: T0413/Current Popular IT II 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.
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
Writing Basic SQL SELECT Statements
SQL – Entire Select.
Chapter 4 Summary Query.
Database Principles Constructed by Hanh Pham based on slides from: “Database Processing, Fundamentals, Design, and Implementation”, D. Kroenke, D. Auer,
Structured Query Language
Writing Basic SQL SELECT Statements
Shelly Cashman: Microsoft Access 2016
Presentation transcript:

1 Structured Query Language (SQL) Pertemuan 09 Matakuliah: F0712 / Lab MS Access Tahun: 2007

2 SQL Framework (1) SQL Statement SELECT [Nama field] FROM [Nama Tabel] SQL Statement dengan Kriteria SELECT [Nama field] FROM [Nama Tabel] WHERE [Kriteria/Kondisi]

3 Reading Specified Columns from a Single Table (1) Suppose we want to obtain just the values of the Department and Buyer columns of the SKU_Data table. SQL Statement : SELECT SKU_Data.Department, SKU_Data.Buyer FROM SKU_Data; or SELECT Department, Buyer FROM SKU_Data

4 Reading Specified Columns from a Single Table (2) Notice that some rows are duplicated in these result.The data in the first and second row, for example is identical. We can eliminate duplicates by using the DISTINCT keyword as follows : SKU_Data Record SQL Result

5 Reading Specified Columns from a Single Table (3) SELECT DISTINCT SKU_Data.Department, SKU_Data.Buyer FROM SKU_Data; SQL Result – Without “DISTINCT” SQL Result – With “DISTINCT”

6 Reading Specified Rows from a Single Table (1) Suppose we want all the columns of the SKU_Data table, but we want only the rows for the Water Sport Department. We can obtain that result by using the WHERE clause as follows : SELECT SKU_Data.SKU, SKU_Data.SKU_Description, SKU_Data.Department, SKU_Data.Buyer FROM SKU_Data WHERE (((SKU_Data.Department)='Water Sport')); or

7 Reading Specified Rows from a Single Table (2) SELECT * FROM SKU_Data WHERE Department='Water Sport' The result of the SQL Statement is In a WHERE clause, if the coloumns contains text or date data, the comparison values must be enclosed in single quotation marks (‘ ‘). If the columns contains numeric data, however, the comparison values need not be in quotes.

8 Reading Specified Rows from a Single Table (3) To find all of the SKU rows with a value greater than , we could code : SELECT * FROM SKU_Data WHERE SKU > The Result is :

9 Reading Specified Columns and Specified Rows from a Single Table (1) Example : to obtain the SKU_Description and Department of all products in the Climbing department, we specify : SELECTSKU_Description, Department FROMSKU_Data WHEREDepartment = ‘Climbing’ Or SELECT SKU_Data.SKU_Description, SKU_Data.Department FROM SKU_Data WHERE (((SKU_Data.Department)='Climbing'));

10 Reading Specified Columns and Specified Rows from a Single Table (2) The result is

11 SORTING If you want the DBMS to display the rows in a particular order, you can use the ORDER BY phrase. For example, the SQL statement : SELECT* FROMORDER_ITEM ORDER_BYOrderNumber Will result in the following :

12 SORTING We can sort by two columns by adding a second column name. For example : to sort first by OrderNumber and then by Price within Order Number. For example, the SQL statement : SELECT * FROM ORDER_ITEM ORDER_BY OrderNumber, Price; Will result in the following :

13 WHERE Clause Options (1) Compound WHERE Clauses  SQL WHERE clauses can include multiple conditions by using AND, OR, IN, and NOT IN operators. For example : to find all of the rows of SKU_Data that have a Department named Water Sport and a Buyer named Nancy Meyers.

14 WHERE Clause Options (2) We can code : SELECT* FROMSKU_Data WHEREDepartment = ‘Water Sport’ ANDBuyer = ‘Nancy Meyers’; The result is :

15 WHERE Clause Options (3) Using OR condition  to find all of the rows in SKU_DATA for either that Camping or Climbing. We could code : SELECT* FROMSKU_DATA WHEREDepartment = ‘Camping’ ORDepartment = ‘Climbing’

16 WHERE Clause Options (4) Using IN operator  We want to obtain all of the rows in SKU_DATA for buyers Nancy Meyers, Cindy Lo, and Jerry Martin. We could code : SELECT* FROMSKU_DATA WHEREBuyer IN (‘Nancy Meyers, Cindy Lo, Jerry Martin’) Using NOT IN operator  to find rows of SKU_DATA for which the buyer is someone other than Nancy Meyers,Cindy Lo, or Jerry Martin.

17 WHERE Clause Options (4) Using NOT IN operator  to find rows of SKU_DATA for which the buyer is someone other than Nancy Meyers,Cindy Lo, or Jerry Martin. We could code : SELECT* FROMSKU_DATA WHEREBuyer NOT IN (‘Nancy Meyers, Cindy Lo, Jerry Martin’)

18 WHERE Clause Options (4) Ranges in WHERE Clauses SQL Statement : SELECT [Field] FROM[Table] WHERE[Condition] BETWEEN [Condition] AND [Condition] Wildcards in WHERE Clauses Using keyword “LIKE”

19 Performing Calculations in SQL Queries (1) Using SQL Built-in Functions –SUM –AVG –MIN –MAX –COUNT Example : we want to know the sum of Order Total for all of the orders in Retail_Order. We can code : SELECTSUM (OrderTotal) FROMRetail_Order

20 Performing Calculations in SQL Queries (2) Arithmetic in SELECT Statements. Example : –Quantity*Price AS EP  to compute the extended price. –Quantity*Price AS EP, ExtendedPrice  to compare this computed value to the stored value of ExtendedPrice. –Etc.

21 Grouping Using the GROUP BY keyword. Using the ORDER BY keyword. Using the HAVING keyword

22 Querying Two or More Tables with SQL (1) Querying Multiple Tables with Subqueries. Querying Multiple Tables with Joins. Comparing Subqueries and Joins.