Access Query Builder: Building Queries with the Principle of Least Information Karl Lieberherr.

Slides:



Advertisements
Similar presentations
SQL: The Query Language Part 1 R &G - Chapter 5 Life is just a bowl of queries. -Anon (not Forrest Gump)
Advertisements

พีชคณิตแบบสัมพันธ์ (Relational Algebra) บทที่ 3 อ. ดร. ชุรี เตชะวุฒิ CS (204)321 ระบบฐานข้อมูล 1 (Database System I)
TURKISH STATISTICAL INSTITUTE 1 /34 SQL FUNDEMANTALS (Muscat, Oman)
1 Advanced SQL Queries. 2 Example Tables Used Reserves sidbidday /10/04 11/12/04 Sailors sidsnameratingage Dustin Lubber Rusty.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 SQL: Queries, Programming, Triggers Chapter 5 Modified by Donghui Zhang.
1 Query-by-Example (QBE). 2 v A “GUI” for expressing queries. –Based on the Domain Relational Calulus (DRC)! –Actually invented before GUIs. –Very convenient.
INFS614, Fall 08 1 Relational Algebra Lecture 4. INFS614, Fall 08 2 Relational Query Languages v Query languages: Allow manipulation and retrieval of.
CS 166: Database Management Systems
Database Management Systems 3ed, Online chapter, R. Ramakrishnan and J. Gehrke1 Query-by-Example (QBE) Online Chapter Example is the school of mankind,
5/15/2015Lecture 31 CS 222 Database Management System Spring Lecture 3 Korra Sathya Babu Department of Computer Science NIT Rourkela.
SQL Part II: Advanced Queries. 421B: Database Systems - SQL Queries II 2 Aggregation q Significant extension of relational algebra q “Count the number.
CS 405G: Introduction to Database Systems
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Query-by-Example (QBE) Chapter 6 Example is the school of mankind, and they will learn at no.
SQL (2).
M ATH IN SQL. 222 A GGREGATION O PERATORS Operators on sets of tuples. Significant extension of relational algebra. SUM ( [DISTINCT] A): the sum of all.
By relieving the brain of all unnecessary work, a good notation sets it free to concentrate on more advanced problems, and, in effect, increases the mental.
1 SQL: Structured Query Language (‘Sequel’) Chapter 5.
By relieving the brain of all unnecessary work, a good notation sets it free to concentrate on more advanced problems, and, in effect, increases the mental.
1 SQL (Simple Query Language). 2 Query Components A query can contain the following clauses –select –from –where –group by –having –order by Only select.
FALL 2004CENG 351 File Structures and Data Management1 SQL: Structured Query Language Chapter 5.
Lecture 4: Relational algebra
CPSC-608 Database Systems Fall 2011 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #3.
1 The Oracle Database System Querying the Data Database Course The Hebrew University of Jerusalem.
Mark Dixon Page 1 02 – Queries: Query by Example.
1 Advanced SQL. 2 Consider the following relations: –pupil (pupil_name, address, class, birthyear) –subject (subject_name, class, teacher) –grades (pupil_name,
Relational Algebra, R. Ramakrishnan and J. Gehrke (with additions by Ch. Eick) 1 Relational Algebra.
CS 370 Database Systems Lecture 13 Introduction to SQL.
LeongHW, SoC, NUS (UIT2201: Database) Page 1 © Leong Hon Wai, Animation of SQL Queries To illustrate three SQL queries: –Q1: simple select (one.
CS 370 Database Systems Lecture 12 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,
SQL Examples CS3754 Class Note 11 CS3754 Class Note 11, John Shieh,
Database Management Systems,1 Relational Calculus.
CS 370 Database Systems Lecture 11 Relational Algebra.
CS1100: Microsoft Access Managing Data in Relational Databases Created By Martin Schedlbauer CS11001Microsoft Access - Introduction.
1.1 CAS CS 460/660 Introduction to Database Systems Relational Algebra.
ICS 321 Fall 2011 The Relational Model of Data (i) Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 8/29/20111Lipyeow.
1 Database Systems ( 資料庫系統 ) October 24, 2005 Lecture #5.
1 CSE 2337 Introduction to Data Management Access Book – Ch 1.
Database Management Systems 1 Raghu Ramakrishnan Relational Algebra Chpt 4 Xin Zhang.
DATA RETRIEVAL WITH SQL Goal: To issue a database query using the SELECT command.
ICS 321 Spring 2011 The Database Language SQL (iii) Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 3/14/20111Lipyeow.
Database Management Systems, R. Ramakrishnan1 Relational Algebra Module 3, Lecture 1.
CMPT 258 Database Systems SQL Queries (Chapter 5).
SQL II.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Management Systems Chapter 5 SQL.
CS 405G: Introduction to Database Systems Instructor: Jinze Liu Fall 2007.
Agenda for Class - 03/04/2014 Answer questions about HW#5 and HW#6 Review query syntax. Discuss group functions and summary output with the GROUP BY statement.
QUERY CONSTRUCTION CS1100: Data, Databases, and Queries CS1100Microsoft Access1.
SQL: The Query Language Part 1 R &G - Chapter 5 The important thing is not to stop questioning. Albert Einstein.
COMP 430 Intro. to Database Systems Grouping & Aggregation Slides use ideas from Chris Ré and Chris Jermaine. Get clickers today!
Access Test Solutions Fall 2014 Questions 7 and 8 Karl Lieberherr.
SQL CS 186, Spring 2007, Lecture 7 R&G, Chapter 5 Mary Roth   The important thing is not to stop questioning. Albert Einstein Life is just a bowl of.
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.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Algebra Chapter 4, Part A.
1 CS122A: Introduction to Data Management Lecture 9 SQL II: Nested Queries, Aggregation, Grouping Instructor: Chen Li.
Slides are reused by the approval of Jeffrey Ullman’s
01/31/11 SQL Examples Edited by John Shieh CS3754 Classnote #10.
CPSC-310 Database Systems
Access Patterns Karl Lieberherr 11/8/2018 Access Patterns.
Relational Algebra 461 The slides for this text are organized into chapters. This lecture covers relational algebra, from Chapter 4. The relational calculus.
Access Final Fall 2014 Query 9
Access Quiz.
SQL: The Query Language Part 1
CS4222 Principles of Database System
SQL: Structured Query Language
Creating complex queries using nesting
Building Queries using the Principle of Simplest Query (POSQ)
Joins and other advanced Queries
Topic 12 Lesson 2 – Retrieving Data with Queries
Presentation transcript:

Access Query Builder: Building Queries with the Principle of Least Information Karl Lieberherr

References Richard Rasala Law of Demeter Berkeley CS 186 slides (for example only)

New Rule we follow Leads to queries that are easier to develop and debug!

Principle of Least Information for Query Writing A query does a join of the minimum number of tables to provide the required fields and their correct values. A query also does a projection of the minimum number of fields needed. In addition, a query does exactly one of four things 1.calculated field: There are two kinds: introduce a calculated field 1.without aggregation. 2.using aggregation, i.e., with a Totals-query that does non-trivial aggregation (sum, average, etc.). 2.elimination of duplicates: eliminate duplicate rows. 3.row selection: select a subset of the rows using a condition. Leads to queries that are easier to develop and debug!

Principle of Least Information for Queries 1. Calculated Field 2. Elimination of Duplicates 2. With Aggregation (Totals Query) 3. Selection 1. Without Aggregation

Why minimum information? Don’t want to overload and confuse our brains.

What is minimized? Minimum number of tables to achieve correct results. Minimum number of fields are selected (projection) to achieve correct result. Each query implements one task involving a minimum but correct join, and a minimum projection and one of introducing a calculated field, possibly with aggregation, elimination of duplicates and row selection. We minimize the operations performed by a query to one of the above.

Pure join If you need a pure join of tables, do a row selection without a condition.

Example We use the sailors database from a lecture at Berkeley.

Example Database sidsnameratingage 1Fred722 2Jim239 3Nancy827 Sailors sidbidday 11029/ /13 Reserves bidbnamecolor 101Ninared 102Pintablue 103Santa Mariared Boats

Find sailors who reserved two or more boats Next slide shows a confusing way of writing a query!

Same Using Nested Query: Find sailors who reserved two or more boats Subquery CountReservations not shown. It counts the number of reservations per sailor. We assume the names are unique; otherwise we need to add the disambiguation pattern.