Computer Science & Engineering 2111 Inner Joins and Advanced Queries 1CSE 2111 Lecture-Advanced Queries.

Slides:



Advertisements
Similar presentations
© 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.
Advertisements

Tutorial 3 Queries and Table Relationships
Concepts of Database Management Seventh Edition
Concepts of Database Management Sixth Edition
Concepts of Database Management Seventh Edition
The University of Akron Dept of Business Technology Computer Information Systems The Relational Model: Query-By-Example (QBE) 2440: 180 Database Concepts.
XP New Perspectives on Microsoft Office Access 2003, Second Edition- Tutorial 3 1 Microsoft Office Access 2003 Tutorial 3 – Querying a Database.
Querying a Database Using the Select Query Window
Querying a Database Microsoft Office Access 2003.
Chapter 2 Querying a Database
Microsoft Access 2010 Chapter 7 Using SQL.
Computer Science & Engineering 2111 CSE 2111 Lecture Basic Criteria in Queries 1CSE 2111 Lecture-Basic Criteria in Queries.
1 Access Lesson 3 Creating Queries Microsoft Office 2010 Introductory Pasewark & Pasewark.
1 Access Lesson 3 Creating Queries Microsoft Office 2010 Introductory.
Concepts of Database Management, Fifth Edition
1 Microsoft Access 2002 Tutorial 3 – Querying a Database.
CS&E 1111 AcQueries Writing Simple Queries in Access Displaying on specific data fields Filtering data using criteria Objectives: Learn how to use the.
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.
With Microsoft Office 2007 Introductory© 2008 Pearson Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Office 2007 Introductory.
CS&E 1111 AcQueries Querying in Access Sorting data Aggregating Data Performing Calculations Objectives: Learn how to use the Access Query Design Tool.
CS&E 1111 AcInnerJoins Inner Joins Objectives: Creating Queries with data from Multiple Tables Joining two tables using an Inner Join Referential Data.
Copyright 2007, Paradigm Publishing Inc. ACCESS 2007 Chapter 4 BACKNEXTEND 4-1 LINKS TO OBJECTIVES Query Design Query Criteria Modify a Query Using OR.
1 Chapter 7 Query-By-Example by Monica Chan CS157B Professor Lee.
Database Queries. Queries Queries are questions used to retrieve information from a database. Contain criteria to specify the records and fields to be.
Analyzing Data For Effective Decision Making Chapter 3.
Concepts of Database Management Seventh Edition
Computer Science & Engineering 2111 Lecture 11 Querying a Database 1.
Using Special Operators (LIKE and IN)
 Agenda 2/20/13 o Review quiz, answer questions o Review database design exercises from 2/13 o Create relationships through “Lookup tables” o Discuss.
Querying a Database Access Project 2. 2 What is a Query?  In general, a query is a form of questioning, in a line of inquiry. A query may also refer.
Part II. Query Types On the design query table pane, right click and the cascading window will appear.
XP Chapter 3 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Analyzing Data For Effective Decision Making Chapter.
Computer Science & Engineering 2111 Querying a Database 1CSE 2111 Lecture- Querying a Database.
Computer Science & Engineering 2111 CSE 2111 Lecture Multiple and Compound Criteria in Queries 1 CSE 2111 Lecture-Multiple and Compound Criteria in Queries.
Copyright 2008 McGraw-Hill Ryerson 1 TECHNOLOGY PLUG-IN T7 PROBLEM SOLVING USING ACCESS.
Chapter 3 Query and Report. Agenda Report types Report contents Report creation Report design view Query and dynaset Function and grouping Action query.
Pasewark & Pasewark 1 Access Lesson 3 Creating Queries Microsoft Office 2007: Introductory.
McGraw-Hill/Irwin © 2008 The McGraw-Hill Companies, All Rights Reserved Plug-In T7: Problem Solving Using Access 2007 Business Driven Technology.
Database Applications – Microsoft Access Lesson 4 Working with Queries 36 Slides in Presentation.
Reports and Queries Chapter 3 – Access text Reports – Page Queries – Page
What are queries? Queries are a way of searching for and compiling data from one or more tables. Running a query is like asking a detailed question of.
You can sort Access data so you can view records in the order you want to view them, and you can filter data so you only see the records you want to see.
Computer Science & Engineering 2111 Outer Joins 1CSE 2111 Lecture- Inner Vs. Outer Jioins.
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
IS201 Agenda: 09/19  Modify contents of the database.  Discuss queries: Turning data stored in a database into information for decision making.  Create.
T7-1 LEARNING OUTCOMES – ACCESS PROBLEM SOLVING 1.Describe the process of using the Simple Query Wizard using Access 2.Describe the process of using the.
XP New Perspectives on Microsoft Access 2002 Tutorial 31 Microsoft Access 2002 Tutorial 3 – Querying a Database.
Computer Science & Engineering 2111 Lecture 13 Outer Joins 1.
© Jalal Kawash Database Queries Peeking into Computer Science.
1 Query Name:Query 1Tables Required:People/Violations Foreign Keys:LIS#Join Type:Inner Field LastNameFirstNameLIS#State Table People Violations Total Sort.
 Review quiz. Answer questions.  Discuss queries: ◦ What is a query? Turning data stored in a database into information for decision making. ◦ You: Completed.
Computer Science & Engineering 2111 Sorting in Queries 1CSE 2111 Lecture-Advanced Queries.
Paul A. Harris, Ph.D. Director, GCRC Informatics How to use query function in Microsoft Access.
McGraw-Hill/Irwin © 2008 The McGraw-Hill Companies, All Rights Reserved Plug-In T7: Problem Solving Using Access 2007 Business Driven Technology.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
Querying in Access Objectives: Learn how to use the Access Query Design Tool manipulate data in Access: Sorting data Aggregating Data Performing Calculations.
Inner Joins Objectives: Creating Queries with data from Multiple Tables Joining two tables using an Inner Join Referential Data Integrity Cascade Update.
Plug-In T7: Problem Solving Using Access 2007
Objectives Create an action query to create a table
Review of Main Database Features
Field Table Sort Show Criteria OR
Microsoft Office Access 2003
Tutorial 3 – Querying a Database
Microsoft Office Access 2003
Aggregations Various Aggregation Functions GROUP BY HAVING.
Access: SQL Participation Project
Query Functions.
Access: Queries III Participation Project
Chapter 3 Query and Report.
New Perspectives on Microsoft
Presentation transcript:

Computer Science & Engineering 2111 Inner Joins and Advanced Queries 1CSE 2111 Lecture-Advanced Queries

Sorting Results in a Query Use the Sorting line - Ascending or Descending to sort the resulting Query Table l To sort multiple fields – The computer will apply sort precedence for sorting fields listed on a query from left to right. l Sorting can be combined with any of the filtering techniques (criteria) we have already discussed. 2 CSE 2111 Lecture-Advanced Queries

Write a query to list the Last name and First name of all clients. The list should be sorted in ascending order by Last name, and then by First name.. Field LNameFName Table Client Sort Ascending Show xx Criteria OR 3 Query Name:NameSortTables Required:Client Foreign Keys:NoneJoin Type:None Major Sort CSE 2111 Lecture-Advanced Queries Minor Sort

The data table The resulting dynaset 4 CSE 2111 Lecture-Advanced Queries

Write a query to list the city and state of all clients The list should be sorted in ascending order by State and then by City. Field CityStateCity Table Client Sort Ascending Show xx Criteria OR 5 Query Name:CityStateSortTables Required:Client Foreign Keys:NoneJoin Type:None Major Sort CSE 2111 Lecture-Advanced Queries Minor Sort

The data table The resulting dynaset 6 CSE 2111 Lecture-Advanced Queries

Field ClientIDLastNameAmount Table Client Payments Sort Show xxx Criteria OR 7 Query Name:InnerJoinExampleTables Required:Client/Payments Foreign Keys:ClientIDJoin Type:Inner CSE 2111 Lecture-Inner Joins in Queries

The resulting dynaset Dynaset only includes records that have matching keys on both tables. This is called an inner join which is the default join type in Access CSE 2111 Lecture-Inner Joins in Queries8 The data tables

CSE 2111 Lecture-Inner Joins in Queries9 Only show the tables on the grid that will be used in your query. Adding extra tables to the QBE grid may cause the dynaset to display incorrectly. All tables shown in the query must either be directly or indirectly linked in order for the query to run correctly. Usually this is the case, but there are some scenarios where you will have to create the relationship on the QBE grid yourself. Guidelines when using more than one table in a query

Write a query that lists the first name, last name, and payment method for each payment made by the client. 10 Query Name:PaymentMethodTables Required:Client/Payments/PaymentMethod Foreign Keys:ClientID/PaymentTypeJoin Type:Inner Field First NameLast NameMethodType Table Client Payments Total Sort Show xxx Criteria OR CSE 2111 Lecture-Aggregate Fields in Queries

11 CSE 2111 Lecture-Aggregate Fields in Queries The resulting dynaset The data tables

You have decided to give all clients a 10% break on each charge they have made. Write a query to list the ClientID, each charge amount before the discount, the discount, and the charge amount after the discount. FieldClientIDAmountDiscount: [Amount] * 0.10New Charge: [Amount] – [Discount] TableClientCharges Sort Showxxxx Criteria OR 12 Query Name:DiscountChargesTables Required:Client/Charges Foreign Keys:ClientIDJoin Type:Inner What if we want to create a field in a query that is the result of a calculation? CSE 2111 Lecture-Calculated Fields in Queries

The resulting dynaset Notice new field names 13 CSE 2111 Lecture-Calculated Fields in Queries

To Aggregate fields in a Query use the Group by feature Use the Group by feature to summarize a field – calculating its average, min, max, sum etc. l Select the group(s) you wish to aggregate - Access will automatically group by the lowest detail level field. l In the desired field(s) select the function (sum, average, etc) using the pull down menu Group by Sum Avg Min Max Count StDev Var First Last Expression Where 14 CSE 2111 Lecture-Aggregate Fields in Queries

Query design grid's Total Row options: Group By: Define the groups you want to perform the calculations for. Aggregate Functions: Sum, Avg, Min, Max etc. Where: Specify criteria for a field, so only those records that meet this criteria will be included in the aggregates. Expression: Use if a calculated field is required in the query. Expressions will be calculated AFTER the fields are aggregated. 15 CSE 2111 Lecture-Aggregate Fields in Queries

Write a query that lists how many payments were made by each Client and their total payments. List the First Name, Last Name, the number of payments made, and the total dollar amount of these payments. 16 Query Name:PaymentSummaryTables Required:Client/Payments Foreign Keys:ClientIDJoin Type:Inner Field First NameLast NameClientIDAmount Table Client Payments Total Group by CountSum Sort Show xxxx Criteria OR CSE 2111 Lecture-Aggregate Fields in Queries

Notice new field names 17 CSE 2111 Lecture-Aggregate Fields in Queries The resulting dynaset The data tables

Write a query to summarize by Client, all of the charges made after 5/1/2008. Add a surcharge of 20% to these charges. List the First Name, Last Name, Original Charge and New Charge. 18 Query Name:ChargesSummaryTables Required:Client/Charges Foreign Keys:ClientIDJoin Type:Inner Field First Name Last Name AmountChargeDate New Charge: [SumOfAmount] * 1.20 Table Client Charges Total Group by SumWhereExpression Sort Show xxxx Criteria > #5/1/2008# OR CSE 2111 Lecture-Aggregate Fields in Queries

Notice new field names 19 CSE 2111 Lecture-Aggregate Fields in Queries The resulting dynaset The data tables