Computer Science & Engineering 2111 Lecture 11 Querying a Database 1.

Slides:



Advertisements
Similar presentations
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Copyright © 2006 by The McGraw-Hill Companies,
Advertisements

4d. Structured Query Language – JOIN Operation Lingma Acheson Department of Computer and Information Science IUPUI CSCI N207 Data Analysis with Spreadsheets.
Relational Algebra, Join and QBE Yong Choi School of Business CSUB, Bakersfield.
© 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.
Computer Science & Engineering 2111 Introduction to Database Systems 1CSE 2111-Introduction to Database Systems.
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 Chapter 3 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Analyzing Data For Effective Decision Making.
Using Objects and Properties
Queries and query design What are queries? Questions that can be asked of the data in the tables. Questions can draw on one or more tables and can have.
1 DB Implementation: MS Access Queries. 2 Outline Access Queries ► Query Creation ► Sorting & Filtering ► Query Types ► Dynamic Query.
Interpreting SQL Code. SQL (The language used to query a database) S is used to specify the you want to include. F is used to specify the the selected.
Computer Science & Engineering 2111 CSE 2111 Lecture Querying a Database 1CSE 2111 Lecture- Querying a Database.
CORE 2: Information systems and Databases STORAGE & RETRIEVAL 2 : SEARCHING, SELECTING & SORTING.
Computer Science & Engineering 2111 Introduction to Database Management Systems Relationships and Database Creation 1 CSE 2111 Introduction to Database.
Computer Science & Engineering 2111 CSE 2111 Lecture Basic Criteria in Queries 1CSE 2111 Lecture-Basic Criteria in Queries.
Microsoft Access Database software. What is a database? … a database is an organized collection of data. A collection of data of similar information compiled.
Resources – MS Access Free Online Training Resources  Using an Access database to store and information (2 min)
DB Implementation: MS Access Queries. MS Access Queries Database Queries Core DBA skill From SQL to Query by Example (QBE) What does it do? Find target.
Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1. Chapter 2: Relational Databases and Multi-Table Queries Exploring Microsoft Office.
Copyright © 2003 by Prentice Hall Module 4 Database Management Systems 1.What is a database? Data hierarchy and data organization Field, record, file,
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.
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.
Microsoft Access Lecture -13- By lec. (Eng.) Hind Basil University of Technology Department of Materials Engineering 1.
Access Primer UoN workshop Naivasha, 30 July – 4 August 2006.
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
Introduction to Computers Lesson 10B. home Database A collection of related data or facts.
Introduction to Computers Lesson 10B. home Database A collection of related data or facts.
Computer Science & Engineering 2111 Lecture 10 Introduction to Database Management Systems 1.
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.
Databases: An Overview Chapter 7, Exploring the Digital Domain.
SESSION 3.1 This section covers using the query window in design view to create a query and sorting & filtering data while in a datasheet view. Microsoft.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Part II. Query Types On the design query table pane, right click and the cascading window will appear.
Ch Determine the output displayed from procedures Lab sheet 10.4.
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.
Database Management Systems.  Database management system (DBMS)  Store large collections of data  Organize the data  Becomes a data storage system.
Tutorial 9 Using Action Queries and Advanced Table Relationships.
Computer Science & Engineering 2111 CSE 2111 Lecture NZ Function 1CSE 2111 NZ Function.
Computer Science & Engineering 2111 Outer Joins 1CSE 2111 Lecture- Inner Vs. Outer Jioins.
The Advantage Series © 2004 The McGraw-Hill Companies, Inc. All rights reserved Creating Select Queries Chapter 6 Microsoft Office Access 2003.
IS201 Agenda: 09/19  Modify contents of the database.  Discuss queries: Turning data stored in a database into information for decision making.  Create.
Access Chapter 1: Intro to Access Objectives Navigate among objects in Access database Difference between working in storage and memory Good database file.
Computer Science & Engineering 2111 Lecture 13 Outer Joins 1.
SQL SELECT Getting Data from the Database. Basic Format SELECT, FROM WHERE (=, >, LIKE, IN) ORDER BY ; SELECT LastName, FirstName, Phone, City FROM Customer.
1 Query Name:Query 1Tables Required:People/Violations Foreign Keys:LIS#Join Type:Inner Field LastNameFirstNameLIS#State Table People Violations Total Sort.
Filters, Queries and Reports. Filters Limit the data, creating a dataset, or partial view of the whole database Single use – filters do not save with.
Computer Science & Engineering 2111 Sorting in Queries 1CSE 2111 Lecture-Advanced Queries.
® Microsoft Access 2010 Tutorial 9 Using Action Queries and Advanced Table Relationships.
VOCAB REVIEW. A field that can be computed from other fields Calculated field Click for the answer Next Question.
Computer Science & Engineering 2111 Inner Joins and Advanced Queries 1CSE 2111 Lecture-Advanced Queries.
DAY 20: ACCESS CHAPTERS 5, 6, 7 Larry Reaves October 28,
Writing Simple Queries in Access
Introduction to Database Systems
Basic Criteria in Queries
Inner Joins Objectives: Creating Queries with data from Multiple Tables Joining two tables using an Inner Join Referential Data Integrity Cascade Update.
Objectives Create an action query to create a table
Basic Criteria in Queries
Introduction to Database Systems
Database Queries.
DB Implementation: MS Access Queries
Lesson 3 Chapter 10.
DB Implementation: MS Access Queries
Presentation transcript:

Computer Science & Engineering 2111 Lecture 11 Querying a Database 1

What is a Database Query? 2 A request for information from a database To extract information from the Database you must use a Query which is a “question” or “request” – Criterion An expression that tells the DBMS which records to retrieve Make up of conditions – Can be one conditions or many When you run the query a dynaset, or subset of the database is displayed. You can make changes to this dynaset and the changes will be reflected in your database, because the dynaset is just a view of your database.

SQL is the language you use to talk to the database MS Access 2010 supplies a graphical user interface (GUI) called the Query By Example Grid or (QBE) grid MS Access 2010 creates the SQL for you. 3 Structured Query Language (SQL)

4 Query By Example (QBE) Grid SQL Created from QBE Grid Dynaset created when Query is Run

Create a list of clients by first and and last name 5

The resulting dynaset: What happens if we later change the last name of John Smith to Jones on the Client Table and re-run the query? 6

Write a query to list the First Name and Last Name and state for all clients who live in Ohio. Field FirstNameLastNameState Table Client Sort Show xxx Criteria “oh” OR 7 Query Name: Ohio Residents Tables Required: Client Foreign Keys: None Join Type: None When typing in any non-numeric criteria, always surround the criteria with quotes.

The data table The resulting dynaset 8

Wild cards in Criteria An asterisk * replaces any number of characters Used with the keyword, Like – Like “C*” – in Product Name field will select c, Cookie, cake. – Like “*cookie*” - in Product Name field will select all records that include the word cookie in the Product Name field A ? replaces a single character – Like “B?” – in the Category field w ill select BE & BA 9

Write a query to list the First Name and Last Name for all clients who live within the 614 area code. Field FirstNameLastNameHomePhone Table Client Sort Show xx Criteria Like “614*” OR 10 Query Name: Phone#614 Tables Required: Client Foreign Keys: None Join Type: None

The resulting dynaset 11 The data table

Write a query to list the First Name and Last Name of all clients who DO NOT live within the 614 area code. Field FirstNameLastNameHomePhone Table Client Sort Show xx Criteria Not Like “614*” OR 12 Query Name: NotPhone#614 Tables Required: Client Foreign Keys: None Join Type: None

The resulting dynaset 13 The data table

Relational operators in a query =, =, <>, With Numbers <= 10 values of less than or equal to 10 With Text < “G” text beginning with letters A through F > “Jones” text from Jones through end The appropriate expression is placed in the field where this data if found. 14

Write a query to list the First Name, Last Name, amount and payment date for all clients who paid $200 or more. Field FirstNameLastNameAmountPaymentDate Table Client Payments Sort Show xx x Criteria > 200 OR 15 Query Name:GreaterThanExampleTables Required:Client/Payments Foreign Keys:ClientIDJoin Type:Inner

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 16 The data tables

For multiple conditions in the same field use Boolean Operators - AND, OR, NOT “BE or “BA” >5 AND <10 NOT “BE” For conditions in multiple fields the placement of your arguments determines the Boolean relationship between those arguments If a criteria is on the same line it is automatically considered an AND If a criteria is on a separate line it is automatically considered an OR 17

Write a query to list the First Name, Last Name, and amount for all clients who paid $250 or more or made payments of less than $ Query Name: Example1Tables Required: Client/Payments Foreign Keys: ClientIDJoin Type:Inner Field FirstNameLastNameAmount Table Client Payments Sort Show xx Criteria >= 250 OR < 75 OR Query Name: Example2Tables Required: Client/Payments Foreign Keys: ClientIDJoin Type:Inner Field FirstNameLastNameAmount Table Client Payments Sort Show xx Criteria >= 250 or < 75 OR

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 19 The data tables

Write a query to list the First Name, Last Name, amount and payment date for all clients who paid more than $100 on or after 3/3/2008. Field FirstNameLastNameAmountPaymentDate Table Client Payments Sort Show xxxx Criteria > 100>= #3/3/2008# OR 20 Query Name:AndExampleTables Required:Client/Payments Foreign Keys:ClientIDJoin Type:Inner

The resulting dynaset 21 The data tables (partial view)

Write a query to list the First Name and Last Name of all clients who made payments between 1/1/2008 and 3/8/2008. Field FirstNameLastNamePaymentDate Table Client Payments Sort Show xxx Criteria Between #1/1/2008# And #3/8/2008# OR 22 Query Name:BetweenExampleTables Required:Client/Payments Foreign Keys:ClientIDJoin Type:Inner

The resulting dynaset 23 The data tables