Building Queries using the Principle of Simplest Query (POSQ)

Slides:



Advertisements
Similar presentations
Working with Tables 1 of 5. Working with Tables 2 of 5.
Advertisements

Access 2007 ® Use Databases How can Microsoft Access 2007 help you structure your database?
CHAPTER OBJECTIVE: NORMALIZATION THE SNOWFLAKE SCHEMA.
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. ACCESS 2007 M I C R O S O F T ® THE PROFESSIONAL APPROACH S E R I E S Lesson 10 – Designing.
Mark Dixon Page 1 06 – Expression Builder. Mark Dixon Page 2 Session Aims & Objectives Aims –To use expressions to perform more complex calculations in.
XP Chapter 3 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Analyzing Data For Effective Decision Making.
Microsoft Access 2010 Chapter 7 Using SQL.
Access 2007 ® Use Databases How can Access help you to find and use information?
Access Query Builder: Building Queries with the Principle of Least Information Karl Lieberherr.
Sorting data and Other selection Techniques Ordering data results Allows us to view our data in a more meaningful way. Rather than just a list of raw.
DATA, DATABASES, AND QUERIES Managing Data in Relational Databases CS1100Microsoft Access - Introduction1.
DATA, DATABASES, AND QUERIES Managing Data in Relational Databases CS1100Microsoft Access - Introduction1 Created By Martin Schedlbauer
1 Access Lesson 3 Creating Queries Microsoft Office 2010 Introductory Pasewark & Pasewark.
Lesson 31: Querying a Database. 2 Learning Objectives After studying this lesson, you will be able to:  Create, save, and run select queries  Design.
Copyright 2007, Paradigm Publishing Inc. ACCESS 2007 Chapter 4 BACKNEXTEND 4-1 LINKS TO OBJECTIVES Query Design Query Criteria Modify a Query Using OR.
Analyzing Data For Effective Decision Making Chapter 3.
Access 2013 Microsoft Access 2013 is a database application that is ideal for gathering and understanding data that’s been collected on just about anything.
1 Single Table Queries. 2 Objectives  SELECT, WHERE  AND / OR / NOT conditions  Computed columns  LIKE, IN, BETWEEN operators  ORDER BY, GROUP BY,
Reports 5.02 Understand database queries, forms, and reports used in business.
CS1100: Microsoft Access Managing Data in Relational Databases Created By Martin Schedlbauer CS11001Microsoft Access - Introduction.
CREATING COMPLEX QUERIES WITH NESTED QUERIES CS1100: Data, Databases, and Queries CS1100Microsoft Access1.
Exploring Microsoft Access Chapter 6 Many-to-Many Relationships: A More Complex System.
Access 2007 ® Use Databases How can Microsoft Access 2007 help you structure your database?
CREATING COMPLEX QUERIES WITH NESTED QUERIES CS1100: Data, Databases, and Queries CS1100Microsoft Access1.
1 Database Systems Introduction to Microsoft Access Part 2.
Pasewark & Pasewark 1 Access Lesson 3 Creating Queries Microsoft Office 2007: Introductory.
Microsoft Office 2003: Advanced 1 ADVANCED MICROSOFT ACCESS Lesson 10 – Analyzing Data.
1 Access Lesson 3 Creating Queries. 2 Creating a Query with the Simple Query Wizard Query-- database object that lets you ask the database about the data.
SqlExam1Review.ppt EXAM - 1. SQL stands for -- Structured Query Language Putting a manual database on a computer ensures? Data is more current Data is.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at
QUERY CONSTRUCTION CS1100: Data, Databases, and Queries CS1100Microsoft Access1.
Lesson 4: Querying a Database. 2 Learning Objectives After studying this lesson, you will be able to:  Create, save, and run select queries  Set query.
Sorting data and Other selection Techniques Ordering data results Allows us to view our data in a more meaningful way. Rather than just a list of raw.
COMP 430 Intro. to Database Systems Grouping & Aggregation Slides use ideas from Chris Ré and Chris Jermaine. Get clickers today!
Database (Microsoft Access). Database A database is an organized collection of related data about a specific topic or purpose. Examples of databases include:
Databases: What they are and how they work
Prepared By: Bobby Wan Microsoft Access Prepared By: Bobby Wan
IST 220 – Intro to Databases
GO! with Microsoft Office 2016
Querying in Access Objectives: Learn how to use the Access Query Design Tool manipulate data in Access: Sorting data Aggregating Data Performing Calculations.
Microsoft Office Illustrated Introductory, Windows Vista Edition
Database Normalization
GO! with Microsoft Access 2016
Microsoft Office Illustrated Fundamentals
ACF5904 AIS Tutorial 4.
Microsoft Access 2003 Illustrated Complete
Building and Using Queries
Access Busn 216.
Access Patterns Karl Lieberherr 11/8/2018 Access Patterns.
GO! with Microsoft® Access e
Data warehouse Design Using Oracle
Access Quiz.
Aggregations Various Aggregation Functions GROUP BY HAVING.
Microsoft Official Academic Course, Access 2016
Order Database – ER Diagram
Structured Query Language – The Fundamentals
M1G Introduction to Database Development
Contents Preface I Introduction Lesson Objectives I-2
From and Report.
Topic 12 Lesson 1 – Data and databases
Creating complex queries using nesting
Lessons Vocabulary Access 2016.
Joins and other advanced Queries
Topic 12 Lesson 2 – Retrieving Data with Queries
Microsoft Office Illustrated Introductory, Windows XP Edition
Shelly Cashman: Microsoft Access 2016
Microsoft Access Date.
Advanced Tables Access Lesson 9.
Presentation transcript:

Building Queries using the Principle of Simplest Query (POSQ) Topic 13 Lesson 2 – Examples using POSQ

Example Query 1: List Order Dates from the Orders Tables Query: List the OrderDates where the Quantity of an item ordered is at least 2. Easy way of implementing query with POSQ: Selection query: select subset of OrderDates with quantity > 2. Elimination of Duplicates. SE : SELECT rows with criteria quantity > 2, then ELIMINATE Duplicates with “Group by”

First subquery: Selection

2nd Subquery: Elimination of Duplicates

Example Query 2: Total for each Order Query: Calculate the total for each order. List the OrderId, OrderDate, and OrderTotal. Easy way of implementing query with POSQ: Widening query: calculate the extended price for each line item. Aggregation query: calculate the total for each order. WA : WIDEN by adding a calculated field, then aggregate the extended price column while grouping the column by OrderId.

Subquery 1: Widening Example: Calculated Field with an ExtendPrice Alias Note: Save query as QOrder1a-ExtendedPrice

Subquery 2: Sum ExtendedPrice for each Order Design View Datasheet View Note: OrderTotal is an alias for the sum of the ExtendedPrice values in each order group. Each order group is defined by the distinct OrdID values. Save Query as QOrder1-Total

Example Query 3: List Order Ids with Order Totals Above 1000 Design View Datasheet View Note: Nest queries to solve more complex queries. This query takes advantage of the previously written QOrder1-Totals query to answer this query

Query Example 4: Count the number of Orders each customer placed Design View Datasheet View Note: When grouping or calculating aggregations by contacts the ContactId (primary key) must be present in the query. If it is not present, then you do not have a GROUP for each contact; this may lead to INCORRECT RESULTS!

Summary Microsoft Access provides a friendly user interface for developing queries. However, the interpretation of the query by the database may not be what you intended. Apply the POSQ to each query, this will allow you to break the query into simple sub-queries that can be combined to solve the query.