Lecture 7: Two-Table Queries

Size: px
Start display at page:

Download "Lecture 7: Two-Table Queries"

Transcription

1 Lecture 7: Two-Table Queries CS1106/CS5021/CS6503 Introduction to Relational Databases Dr Kieran T. Herley Department of Computer Science University College Cork KH (10/10/17) Lecture 7: Two-Table Queries / 1

2 Summary Two-table database designs. Cartesian product. Simple (inner) joins and self joins. KH (10/10/17) Lecture 7: Two-Table Queries / 1

3 Favourite Foods DB Revisited persons person id first name last name gender date of birth street town county Aoife Ahern F Brown Street Cork Cork Barry Barry M Green Street Tralee Kerry Ciara Callaghan F White Avenue Limerick Limerick Declan Duffy M Black Crescent Cork Cork Eimear Early F Red Square Thurles Tipperary Fionn Fitzgerald M Yellow Lane Bandon Cork favourite foods person id food Crisps Beer Nutella Chips Chocolate Ice Cream Chocolate Pizza Beer Crisps Pizza Chocolate Brussels Sprouts Ice Cream Nutella persons table captures individuals details favourite foods captures who likes what e.g (Fionn Fitzgerald) is partial to ice cream and Nutella KH (10/10/17) Lecture 7: Two-Table Queries / 1

4 Why Not Just Mash the Two Tables Together? Redundancy details) Anomalies persons and foods person id first name last name food Aoife Ahern Crisps Aoife Ahern Beer Aoife Ahern Nutella Barry Barry Chips Barry Barry Chocolate Fionn Fitzgerald Nutella Some information is replicated several times (e.g. Aoife s What is we wish to update Aoife s details e.g. change address Need to modify multiple rows otherwise table contains inconsistent information DB designers go to great length to avoid this sort of situation KH (10/10/17) Lecture 7: Two-Table Queries / 1

5 Queries That Span Tables persons person id first name last name gender date of birth street town county Aoife Ahern F Brown Street Cork Cork Barry Barry M Green Street Tralee Kerry Ciara Callaghan F White Avenue Limerick Limerick Declan Duffy M Black Crescent Cork Cork Eimear Early F Red Square Thurles Tipperary Fionn Fitzgerald M Yellow Lane Bandon Cork favourite foods person id food Crisps Beer Nutella Chips Chocolate Ice Cream Chocolate Pizza Beer Crisps Pizza Chocolate Brussels Sprouts Ice Cream Nutella What about queries that require info. from both tables? List the favourite foods of the person(s) named Aoife Ahern List all the persons who like pizza and beer KH (10/10/17) Lecture 7: Two-Table Queries / 1

6 Cartesian Product Cartesian Product The Cartesian product of sets S and T is the set of pairs of the form (s, t), where s S and t T. Example S = {2, 3, 5} T = {a, e, i, o, u} S T = { (2, a), (2, e), (2, i), (2, o), (2, u), (3, a), (3, e), (3, i), (3, o), (3, u), (5, a), (5, e), (5, i), (5, o), (5, u) } Note size of S T is the size of S multiplied by the size of T KH (10/10/17) Lecture 7: Two-Table Queries / 1

7 Cartesian Product In SQL Can use CROSS JOIN to form Cartesian product SELECT FROM persons CROSS JOIN favourite foods; person id first name last name person id food Aoife Ahern Crisps Barry Barry Crisps Ciara Callaghan Crisps Declan Duffy Crisps Eimear Early Crisps Fionn Fitzgerald Crisps Aoife Ahern Beer Barry Barry Beer Fionn Fitzgerald Nutella # rows() = # rows(persons) # rows(favourite fo # cols() = # cols(persons)+ # cols(favourite foo KH (10/10/17) Lecture 7: Two-Table Queries / 1

8 Cartesian Product In SQL cont d Most rows in cross join are meaningless person id first name last name person id food Aoife Ahern Crisps Barry Barry Crisps Ciara Callaghan Crisps Declan Duffy Crisps Eimear Early Crisps Fionn Fitzgerald Crisps Aoife Ahern Beer Barry Barry Beer Fionn Fitzgerald Nutella KH (10/10/17) Lecture 7: Two-Table Queries / 1

9 Cartesian Product In SQL cont d Most rows in cross join are meaningless, but not all... person id first name last name person id food Aoife Ahern Crisps Barry Barry Crisps Ciara Callaghan Crisps Declan Duffy Crisps Eimear Early Crisps Fionn Fitzgerald Crisps Aoife Ahern Beer Barry Barry Beer Fionn Fitzgerald Nutella KH (10/10/17) Lecture 7: Two-Table Queries / 1

10 Cartesian Product In SQL cont d On closer inspection some rows in the product are potentially meaningful person id first name last name person id food Aoife Ahern Crisps Barry Barry Crisps Ciara Callaghan Crisps Declan Duffy Crisps Eimear Early Crisps Fionn Fitzgerald Crisps Aoife Ahern Beer Barry Barry Beer Fionn Fitzgerald Nutella The highlighted rows are formed by coupling s (i.e. Aoife s) row from the persons table s rows from the favourite foods table These rows collectively contain information on Aoife s weaknesses If only we could filter out the useless rows from the product and retain only the useful ones KH (10/10/17) Lecture 7: Two-Table Queries / 1..

11 Joins In SQL Consider the familiar SELECT-FROM template SELECT FROM X ; here X specifies a table to which query is to be applied SELECT FROM persons JOIN favourite foods ON persons.person id = favourite foods. person id ; applies the SELECT-FROM to a following table (our X for this query) subset of Cartesian product of persons and favourite foods tables but includes only those (combined) rows where the person id value from the persons row and that of the favourite foods match Note use of persons.person_id notation to distinguish between two person id columns in product KH (10/10/17) Lecture 7: Two-Table Queries / 1

12 Joins In SQL cont d for each row-pair (alpha, beta) from persons X favourite_foods do if alpha.person_id and beta.person_id are equal then Include (alpha, beta) in result KH (10/10/17) Lecture 7: Two-Table Queries / 1

13 Back to Our Query SELECT FROM persons JOIN favourite foods ON persons.person id = favourite foods. person id ; person id first name last name person id food Aoife Ahern Crisps Aoife Ahern Beer Aoife Ahern Nutella Barry Barry Chips Barry Barry Chocolate Ciara Callaghan Ice Cream Ciara Callaghan Chocolate Declan Duffy Pizza Declan Duffy Beer Declan Duffy Crisps Eimear Early Pizza Eimear Early Chocolate Eimear Early Brussels Sprouts Fionn Fitzgerald Ice Cream Fionn Fitzgerald Nutella Fifteen rows each formed by glueing together a row from favourite foods with the row from persons that corresponds to the individual whose food preference it is KH (10/10/17) Lecture 7: Two-Table Queries / 1

14 An Example List all the students who like pizza Can use WHERE clause to further filter results SELECT FROM persons JOIN favourite foods ON persons.person id = favourite foods. person id WHERE food = Pizza ; Can interpret as a standard SELECT-FROM-WHERE that is applied to the join of the two tables (on person id values) essentially result of previous query Yields following result person id first name last name person id food Declan Duffy Pizza Eimear Early Pizza KH (10/10/17) Lecture 7: Two-Table Queries / 1

15 A Tidier Version SELECT first name, last name, FROM persons AS p JOIN favourite foods AS f ON p.person id = f. person id WHERE food = pizza ; likes, food Clause persons AS p attaches shorter name (p) to table persons can use p instead of persons throughout query improves readability KH (10/10/17) Lecture 7: Two-Table Queries / 1

16 Reasoning About Join Queries Recall SELECT first name, last name, likes, food FROM persons AS p JOIN favourite foods AS f ON p. person id = f. person id WHERE food = Pizza ; Can be helpful to consider query execution in three stages 1 1 ( Create full Cartesian product C of tables persons and favourite foods) 2 ( Filter C to retain (in C ) only those rows in C that satisfy the ON condition) 3 Filter C to retain (in R) only those rows in C that satisfy the WHERE condition and return R as the result of the query 1 Conceptual model only; actual mechanics of query execurion may follow different approach KH (10/10/17) Lecture 7: Two-Table Queries / 1

17 Example 3 List all pairs of students who hail from the same county (not the same as all those from a specific county) Use just the persons table, but forms join of table with itself (two copies )! KH (10/10/17) Lecture 7: Two-Table Queries / 1

18 Example 3 List all pairs of students who hail from the same county (not the same as all those from a specific county) Use just the persons table, but forms join of table with itself (two copies )! First stab: SELECT p1. first name, p1.last name, and, p2. first name, p2.last name, both come from, p1.county FROM persons AS p1 JOIN persons AS p2 ON p1.county = p2.county; Any problems with this? KH (10/10/17) Lecture 7: Two-Table Queries / 1

19 A Closer Look Query completion Typical row from Cartestian product p id county p id county x Cork y Kerry from persons 1 from persons 2 Typical row from product filtered by ON condition p id county p id county x Cork y Cork from persons 1 from persons 2 KH (10/10/17) Lecture 7: Two-Table Queries / 1

20 A Closer Look Query completion Typical row from Cartestian product p id county p id county x Cork y Kerry from persons 1 from persons 2 Typical row from product filtered by ON condition p id county p id county x Cork y Cork from persons 1 from persons 2 Slight problem Result may contain duplicates (Aoife-Declan and Declan-Aoife) p id county p id county x Cork y Cork y Cork x Cork from persons 1 from persons 2 KH (10/10/17) Lecture 7: Two-Table Queries / 1

21 A Closer Look Query completion Typical row from Cartestian product p id county p id county x Cork y Kerry from persons 1 from persons 2 Typical row from product filtered by ON condition p id county p id county x Cork y Cork from persons 1 from persons 2 Slight problem Result may contain duplicates (Aoife-Declan and Declan-Aoife) p id county p id county x Cork y Cork y Cork x Cork from persons 1 from persons 2 May also contain self-pairs (Aoife-Aoife) p id county p id county x Cork x Cork from persons 1 from persons 2 KH (10/10/17) Lecture 7: Two-Table Queries / 1

22 Our Query First attempt lists each pair twice (Aoife-Declan and Declan-Aoife) and also self pairs like (Aoife-Aoife) SELECT p1. first name, p1.last name, and, p2. first name, p2.last name, both come from, p1.county FROM persons AS p1 JOIN persons AS p2 ON p1.county = p2.county AND p1.person id < p2.person id; The < clause filters out duplicates and self pairs KH (10/10/17) Lecture 7: Two-Table Queries / 1

23 Our Query Again Could rephrase as follows: SELECT p1. first name, p1.last name, and, p2. first name, p2.last name, both come from, p1.county FROM persons AS p1 JOIN persons AS p2 ON p1.county = p2.county WHERE p1.person id < p2.person id; Bothe the ON-condition and WHERE-condition filter rows; so the < criterion can migrate into the latter KH (10/10/17) Lecture 7: Two-Table Queries / 1

24 Who Likes Pizza and Beer? List all those individuals who like pizza and beer Idea: three-way join (persons favourite foods favourite foods) with ON condition that ensures: three-way match on person id favourite foods.food (first copy) should equal Pizza favourite foods.food (second copy) should equal Beer KH (10/10/17) Lecture 7: Two-Table Queries / 1

25 The Query SELECT first name, last name, f1.food, f2.food FROM persons AS p JOIN favourite foods AS f1 JOIN favourite foods AS f2 ON p. person id = f1. person id AND f1.person id = f2.person id AND f1.food = Pizza AND f2.food = Beer ; KH (10/10/17) Lecture 7: Two-Table Queries / 1

26 Our Query Typical row from Cartesian product: p id p id food p id food x y Nutella z Crisps from persons from fav foods 1 from fav foods 2 No meaningful relationship among the fragments from the joinee tables KH (10/10/17) Lecture 7: Two-Table Queries / 1

27 Our Query Typical row from Cartesian product: p id p id food p id food x y Nutella z Crisps from persons from fav foods 1 from fav foods 2 No meaningful relationship among the fragments from the joinee tables Typical row product filtered by ON-condition: p id p id food p id food x x Pizza x Beer from persons from fav foods 1 from fav foods 2 Note person id (here abbrev. to p id) must match up and food values must be Pizza and Beer respectively KH (10/10/17) Lecture 7: Two-Table Queries / 1

28 Note SQL supports several types of join We have been using the INNER JOIN (the default) There are also OUTER, LEFT, RIGHT joins etc. which we may see later KH (10/10/17) Lecture 7: Two-Table Queries / 1

29 Notes and Acknowledgements KH (10/10/17) Lecture 7: Two-Table Queries / 1

Data Definition and Data Manipulation. Lecture 5: SQL s Data Definition Language CS1106/CS5021/CS6503 Introduction to Relational Databases

Data Definition and Data Manipulation. Lecture 5: SQL s Data Definition Language CS1106/CS5021/CS6503 Introduction to Relational Databases and Data Manipulation Lecture 5: SQL s Language CS1106/CS5021/CS6503 Introduction to Relational Databases Dr Kieran T Herley Department of Computer Science University College Cork 2017-2018 So far we ve

More information

Lecture 5: SQL s Data Definition Language

Lecture 5: SQL s Data Definition Language Lecture 5: SQL s Data Definition Language CS1106/CS5021/CS6503 Introduction to Relational Databases Dr Kieran T. Herley Department of Computer Science University College Cork 2017-2018 KH (29/09/17) Lecture

More information

Lecture 3: More SQL Basics CS1106/CS5021/CS6503 Introduction to Relational Databases. Single-Criterion WHERE Conditions. SQL Conditions.

Lecture 3: More SQL Basics CS1106/CS5021/CS6503 Introduction to Relational Databases. Single-Criterion WHERE Conditions. SQL Conditions. Lecture 3: More SQL Basics CS1106/CS5021/CS6503 Introduction to Relational Databases Dr Kieran T. Herley Summary Composite conditions using AND, OR and NOT. The IN operator. Ordering results. Renaming

More information

Lecture 2: SQL Basics CS1106/CS5021/CS6503 Introduction to Relational Databases. Brief Note on Naming Conventions. Our Running Example.

Lecture 2: SQL Basics CS1106/CS5021/CS6503 Introduction to Relational Databases. Brief Note on Naming Conventions. Our Running Example. Lecture 2: SQL Basics CS1106/CS5021/CS6503 Introduction to Relational Databases Dr Kieran T. Herley Summary Review of relation model. Simple SELECT-FROM and SIMPLE-FROM-WHERE queries. SQL s operators.

More information

Lecture 3: More SQL Basics

Lecture 3: More SQL Basics Lecture 3: More SQL Basics CS1106/CS5021/CS6503 Introduction to Relational Databases Dr Kieran T. Herley Department of Computer Science University College Cork 2018/19 KH (11/09/18) Lecture 3: More SQL

More information

Lecture 1: Relational Databases

Lecture 1: Relational Databases Lecture 1: Relational Databases CS1106/CS5021/CS6503 Introduction to Relational Databases Dr Kieran T. Herley Department of Computer Science University College Cork 2017-2018 KH (12/09/17) Lecture 1: Relational

More information

Lecture 2: SQL Basics

Lecture 2: SQL Basics Lecture 2: SQL Basics CS1106/CS5021/CS6503 Introduction to Relational Databases Dr Kieran T. Herley Department of Computer Science University College Cork 2017-2018 KH (19/09/17) Lecture 2: SQL Basics

More information

Lecture 4: SQL Data Manipulation Basics

Lecture 4: SQL Data Manipulation Basics Lecture 4: SQL Data Manipulation Basics Data Manipulation Dr Kieran T. Herley Department of Computer Science University College Cork 2017-2018 KH (26/09/17) Lecture 4: SQL Data Manipulation Basics 2017-2018

More information

MANAGING DATA(BASES) USING SQL (NON-PROCEDURAL SQL, X401.9)

MANAGING DATA(BASES) USING SQL (NON-PROCEDURAL SQL, X401.9) Technology & Information Management Instructor: Michael Kremer, Ph.D. Class 6 Professional Program: Data Administration and Management MANAGING DATA(BASES) USING SQL (NON-PROCEDURAL SQL, X401.9) AGENDA

More information

Lecture 15: Database Normalization

Lecture 15: Database Normalization Lecture 15: Database Normalization Dr Kieran T. Herley Department of Computer Science University College Cork 2018/19 KH (12/11/18) Lecture 15: Database Normalization 2018/19 1 / 18 Summary The perils

More information

Advance Database Systems. Joining Concepts in Advanced SQL Lecture# 4

Advance Database Systems. Joining Concepts in Advanced SQL Lecture# 4 Advance Database Systems Joining Concepts in Advanced SQL Lecture# 4 Lecture 4: Joining Concepts in Advanced SQL Join Cross Join Inner Join Outer Join 3 Join 4 Join A SQL join clause combines records from

More information

Review -Chapter 4. Review -Chapter 5

Review -Chapter 4. Review -Chapter 5 Review -Chapter 4 Entity relationship (ER) model Steps for building a formal ERD Uses ER diagrams to represent conceptual database as viewed by the end user Three main components Entities Relationships

More information

Querying Data with Transact SQL

Querying Data with Transact SQL Course 20761A: Querying Data with Transact SQL Course details Course Outline Module 1: Introduction to Microsoft SQL Server 2016 This module introduces SQL Server, the versions of SQL Server, including

More information

A subquery is a nested query inserted inside a large query Generally occurs with select, from, where Also known as inner query or inner select,

A subquery is a nested query inserted inside a large query Generally occurs with select, from, where Also known as inner query or inner select, Sub queries A subquery is a nested query inserted inside a large query Generally occurs with select, from, where Also known as inner query or inner select, Result of the inner query is passed to the main

More information

CMP-3440 Database Systems

CMP-3440 Database Systems CMP-3440 Database Systems Relational DB Languages Relational Algebra, Calculus, SQL Lecture 05 zain 1 Introduction Relational algebra & relational calculus are formal languages associated with the relational

More information

Interview Questions on DBMS and SQL [Compiled by M V Kamal, Associate Professor, CSE Dept]

Interview Questions on DBMS and SQL [Compiled by M V Kamal, Associate Professor, CSE Dept] Interview Questions on DBMS and SQL [Compiled by M V Kamal, Associate Professor, CSE Dept] 1. What is DBMS? A Database Management System (DBMS) is a program that controls creation, maintenance and use

More information

THE RELATIONAL DATABASE MODEL

THE RELATIONAL DATABASE MODEL THE RELATIONAL DATABASE MODEL Introduction to relational DB Basic Objects of relational model Properties of relation Representation of ER model to relation Keys Relational Integrity Rules Functional Dependencies

More information

Follow these steps to get started: o Launch MS Access from your start menu. The MS Access startup panel is displayed:

Follow these steps to get started: o Launch MS Access from your start menu. The MS Access startup panel is displayed: Forms-based Database Queries The topic presents a summary of Chapter 3 in the textbook, which covers using Microsoft Access to manage and query an Access database. The screenshots in this topic are from

More information

Lecture 0: Overview of cs1106/cs6503

Lecture 0: Overview of cs1106/cs6503 Lecture 0: Overview of cs1106/cs6503 cs1106+ Overview Dr Kieran T. Herley Department of Computer Science University College Cork 2018/19 KH (09/10/18) Lecture 0: Overview of cs1106/cs6503 2018/19 1 / 16

More information

Databases. Dr. Richard E. Turner March 5, 2013

Databases. Dr. Richard E. Turner March 5, 2013 Databases Dr. Richard E. Turner (ret26@cam.ac.uk) March 5, 2013 Big-data: Databases Database = structured collection of data Everywhere: Facebook, MySpace, Google, Android (sqlite3), Amazon,... Amazon

More information

Implementing Table Operations Using Structured Query Language (SQL) Using Multiple Operations. SQL: Structured Query Language

Implementing Table Operations Using Structured Query Language (SQL) Using Multiple Operations. SQL: Structured Query Language Implementing Table Operations Using Structured Query Language (SQL) Using Multiple Operations Show Only certain columns and rows from the join of Table A with Table B The implementation of table operations

More information

Chapter 3. The Relational Model. Database Systems p. 61/569

Chapter 3. The Relational Model. Database Systems p. 61/569 Chapter 3 The Relational Model Database Systems p. 61/569 Introduction The relational model was developed by E.F. Codd in the 1970s (he received the Turing award for it) One of the most widely-used data

More information

Section 2.2: Relational Databases

Section 2.2: Relational Databases Page 1 Section 2.2: Relational Databases Databases A database is a set of records that can be manipulated by a computer. Database management systems allow users of the system to perform a variety of operations,

More information

DB Export/Import/Generate data tool

DB Export/Import/Generate data tool DB Export/Import/Generate data tool Main functions: quick connection to any database using defined UDL files show list of available tables and/or queries show data from selected table with possibility

More information

Lecture 4: Basic I/O

Lecture 4: Basic I/O Lecture 4: Basic I/O CS1068+ Introductory Programming in Python Dr Kieran T. Herley Department of Computer Science University College Cork 2017-2018 KH (21/09/17) Lecture 4: Basic I/O 2017-2018 1 / 20

More information

CS Final Exam Review Suggestions

CS Final Exam Review Suggestions CS 325 - Final Exam Review Suggestions p. 1 last modified: 2017-12-06 CS 325 - Final Exam Review Suggestions Based on suggestions from Prof. Deb Pires from UCLA: Because of the research-supported learning

More information

Relational Model History. COSC 416 NoSQL Databases. Relational Model (Review) Relation Example. Relational Model Definitions. Relational Integrity

Relational Model History. COSC 416 NoSQL Databases. Relational Model (Review) Relation Example. Relational Model Definitions. Relational Integrity COSC 416 NoSQL Databases Relational Model (Review) Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Relational Model History The relational model was proposed by E. F. Codd

More information

Database Principles: Fundamentals of Design, Implementation, and Management Ninth Edition Carlos Coronel, Steven Morris, and Peter Rob

Database Principles: Fundamentals of Design, Implementation, and Management Ninth Edition Carlos Coronel, Steven Morris, and Peter Rob Database Principles: Fundamentals of Design, Implementation, and Management Ninth Edition Carlos Coronel, Steven Morris, and Peter Rob Chapter 8 Advanced SQL Relational Set Operators UNION INTERSECT MINUS

More information

Database Systems: Design, Implementation, and Management Tenth Edition. Chapter 8 Advanced SQL

Database Systems: Design, Implementation, and Management Tenth Edition. Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management Tenth Edition Chapter 8 Advanced SQL SQL Join Operators Join operation merges rows from two tables and returns the rows with one of the following:

More information

Chapter 1: Introduction

Chapter 1: Introduction Chapter 1: Introduction Chapter 2: Intro. To the Relational Model Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Database Management System (DBMS) DBMS is Collection of

More information

Relational Algebra. Ron McFadyen ACS

Relational Algebra. Ron McFadyen ACS Relational Algebra Relational algebra is a procedural language operations that can be implemented by a database SQL is non-procedural We will consider some operators and the mapping of SQL Select to RA

More information

Querying Data with Transact-SQL

Querying Data with Transact-SQL Querying Data with Transact-SQL Course: 20761 Course Details Audience(s): IT Professional(s) Technology: Microsoft SQL Server 2016 Duration: 24 HRs. ABOUT THIS COURSE This course is designed to introduce

More information

Databases - Relational Algebra. (GF Royle, N Spadaccini ) Databases - Relational Algebra 1 / 24

Databases - Relational Algebra. (GF Royle, N Spadaccini ) Databases - Relational Algebra 1 / 24 Databases - Relational Algebra (GF Royle, N Spadaccini 2006-2010) Databases - Relational Algebra 1 / 24 This lecture This lecture covers relational algebra which is the formal language underlying the manipulation

More information

Database Lab Lab 6 DML part 3

Database Lab Lab 6 DML part 3 Islamic University of Gaza Faculty of Engineering Department of Computer Engineering Fall 2011 ECOM 4113: Database System Lab Eng. Ahmed Abumarasa Database Lab Lab 6 DML part 3 Data Manipulation Language:

More information

This lecture. Projection. Relational Algebra. Suppose we have a relation

This lecture. Projection. Relational Algebra. Suppose we have a relation This lecture Databases - Relational Algebra This lecture covers relational algebra which is the formal language underlying the manipulation of relations. We follow the notation from Chapter 4 of Ramakrishnan

More information

Project activity sheet 3

Project activity sheet 3 1 Macmillan English Project activity sheet 3 Project: Food bar chart Units 13 18 Learning outcomes By the end of the project, children will have: practised language from Units 13 18 through a group project

More information

G64DBS Database Systems. Lecture 7 SQL SELECT. The Data Dictionary. Data Dictionaries. Different Sections of SQL (DDL) Different Sections of SQL (DCL)

G64DBS Database Systems. Lecture 7 SQL SELECT. The Data Dictionary. Data Dictionaries. Different Sections of SQL (DDL) Different Sections of SQL (DCL) G64DBS Database Systems Lecture 7 SQL SELECT Tim Brailsford Different Sections of SQL (DDL) The Data Definition Language (DDL): CREATE TABLE - creates a new database table ALTER TABLE - alters (changes)

More information

presented by: Tim Haithcoat University of Missouri Columbia

presented by: Tim Haithcoat University of Missouri Columbia 12 presented by: Tim Haithcoat University of Missouri Columbia Introduction Very early attempts to build GIS began from scratch, using limited tools like operating systems & compilers More recently, GIS

More information

Ian Kenny. November 28, 2017

Ian Kenny. November 28, 2017 Ian Kenny November 28, 2017 Introductory Databases Relational Algebra Introduction In this lecture we will cover Relational Algebra. Relational Algebra is the foundation upon which SQL is built and is

More information

CS530 Database Architecture Models. Database Model. Prof. Ian HORROCKS. Dr. Robert STEVENS. and Design The Relational

CS530 Database Architecture Models. Database Model. Prof. Ian HORROCKS. Dr. Robert STEVENS. and Design The Relational 02 - The Relational Database Model CS530 Database Architecture Models and Design Prof. Ian HORROCKS Dr. Robert STEVENS In this Section Topics Covered The basics of the relational model in the context of

More information

Entity Attribute STUDENT TABLE tuples single domain

Entity Attribute STUDENT TABLE tuples single domain Objectives Computer Science 202 Database Systems: Relational Database Model To learn the basic relational database components and concepts. To become familiar with the relational table's components and

More information

Oracle Database 10g: Introduction to SQL

Oracle Database 10g: Introduction to SQL ORACLE UNIVERSITY CONTACT US: 00 9714 390 9000 Oracle Database 10g: Introduction to SQL Duration: 5 Days What you will learn This course offers students an introduction to Oracle Database 10g database

More information

Chapter 3B Objectives. Relational Set Operators. Relational Set Operators. Relational Algebra Operations

Chapter 3B Objectives. Relational Set Operators. Relational Set Operators. Relational Algebra Operations Chapter 3B Objectives Relational Set Operators Learn About relational database operators SELECT & DIFFERENCE PROJECT & JOIN UNION PRODUCT INTERSECT DIVIDE The Database Meta Objects the data dictionary

More information

Unit Assessment Guide

Unit Assessment Guide Unit Assessment Guide Unit Details Unit code Unit name Unit purpose/application ICTWEB425 Apply structured query language to extract and manipulate data This unit describes the skills and knowledge required

More information

Lecture 4: Simple Input-Calculate-Output Programs

Lecture 4: Simple Input-Calculate-Output Programs Lecture 4: Simple Input-Calculate-Output Programs CS1068+ Introductory Programming in Python Dr Kieran T. Herley 2017/18 Department of Computer Science University College Cork input Statement Python s

More information

Querying Data with Transact-SQL

Querying Data with Transact-SQL Course 20761A: Querying Data with Transact-SQL Page 1 of 5 Querying Data with Transact-SQL Course 20761A: 2 days; Instructor-Led Introduction The main purpose of this 2 day instructor led course is to

More information

T-SQL Training: T-SQL for SQL Server for Developers

T-SQL Training: T-SQL for SQL Server for Developers Duration: 3 days T-SQL Training Overview T-SQL for SQL Server for Developers training teaches developers all the Transact-SQL skills they need to develop queries and views, and manipulate data in a SQL

More information

Review The Big Picture

Review The Big Picture CS445 - Introduction to Database Management Systems Fall Semester 2015 LECTURE 6 The Entity-Relationship Model Introduction TEXTBOOK REFERENCE: CHAPTERS 2,3 R&G 1 Review The Big Picture Data Modeling Relational

More information

Certification Exam Preparation Seminar: Oracle Database SQL

Certification Exam Preparation Seminar: Oracle Database SQL Oracle University Contact Us: 0800 891 6502 Certification Exam Preparation Seminar: Oracle Database SQL Duration: 1 Day What you will learn This video seminar Certification Exam Preparation Seminar: Oracle

More information

CS211 Lecture: Database Querying and Updating

CS211 Lecture: Database Querying and Updating CS211 Lecture: Database Querying and Updating last revised 9/30/2004 Objectives: 1. To introduce the relational algebra. 2. To introduce the SQL select statement 3. To introduce the SQL insert, update,

More information

2. Discovery of Association Rules

2. Discovery of Association Rules 2. Discovery of Association Rules Part I Motivation: market basket data Basic notions: association rule, frequency and confidence Problem of association rule mining (Sub)problem of frequent set mining

More information

IT 3203 Introduction to Web Development

IT 3203 Introduction to Web Development IT 3203 Introduction to Web Development Databases and SQL April 7 Notice: This session is being recorded. Copyright 2007 by Bob Brown Disadvantages of File Processing Program-Data Dependence All programs

More information

Review. Relational Query Optimization. Query Optimization Overview (cont) Query Optimization Overview. Cost-based Query Sub-System

Review. Relational Query Optimization. Query Optimization Overview (cont) Query Optimization Overview. Cost-based Query Sub-System Review Relational Query Optimization R & G Chapter 12/15 Implementation of single Relational Operations Choices depend on indexes, memory, stats, Joins Blocked nested loops: simple, exploits extra memory

More information

CPS221 Lecture: Relational Database Querying and Updating

CPS221 Lecture: Relational Database Querying and Updating CPS221 Lecture: Relational Database Querying and Updating last revised 8/5/10 Objectives: 1. To introduce the SQL select statement 2. To introduce the SQL insert, update, and delete statements Materials:

More information

Writing Analytical Queries for Business Intelligence

Writing Analytical Queries for Business Intelligence MOC-55232 Writing Analytical Queries for Business Intelligence 3 Days Overview About this Microsoft SQL Server 2016 Training Course This three-day instructor led Microsoft SQL Server 2016 Training Course

More information

Database Systems: Design, Implementation, and Management Tenth Edition. Chapter 8 Advanced SQL

Database Systems: Design, Implementation, and Management Tenth Edition. Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management Tenth Edition Chapter 8 Advanced SQL Objectives In this chapter, you will learn: How to use the advanced SQL JOIN operator syntax About the different

More information

CPS221 Lecture: Relational Database Querying and Updating

CPS221 Lecture: Relational Database Querying and Updating CPS221 Lecture: Relational Database Querying and Updating Objectives: last revised 10/29/14 1. To introduce the SQL select statement 2. To introduce the SQL insert, update, and delete statements Materials:

More information

Relational Algebra. ICOM 5016 Database Systems. Roadmap. R.A. Operators. Selection. Example: Selection. Relational Algebra. Fundamental Property

Relational Algebra. ICOM 5016 Database Systems. Roadmap. R.A. Operators. Selection. Example: Selection. Relational Algebra. Fundamental Property Relational Algebra ICOM 06 Database Systems Relational Algebra Dr. Amir H. Chinaei Department of Electrical and Computer Engineering University of Puerto Rico, Mayagüez Slides are adapted from: Introduction.

More information

Faloutsos - Pavlo CMU SCS /615

Faloutsos - Pavlo CMU SCS /615 Faloutsos - Pavlo 15-415/615 Carnegie Mellon Univ. School of Computer Science 15-415/615 - DB Applications C. Faloutsos & A. Pavlo Lecture #4: Relational Algebra Overview history concepts Formal query

More information

Chapter 2 Conceptual Modeling. Objectives

Chapter 2 Conceptual Modeling. Objectives Chapter 2 Conceptual Modeling Basic Entity Relationship Diagrams 1 Objectives Definition of terms Importance of data modeling Write good names and definitions for entities, relationships, and attributes

More information

Overview. Carnegie Mellon Univ. School of Computer Science /615 - DB Applications. Concepts - reminder. History

Overview. Carnegie Mellon Univ. School of Computer Science /615 - DB Applications. Concepts - reminder. History Faloutsos - Pavlo 15-415/615 Carnegie Mellon Univ. School of Computer Science 15-415/615 - DB Applications C. Faloutsos & A. Pavlo Lecture #4: Relational Algebra Overview history concepts Formal query

More information

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe CHAPTER 19 Query Optimization Introduction Query optimization Conducted by a query optimizer in a DBMS Goal: select best available strategy for executing query Based on information available Most RDBMSs

More information

Querying Data with Transact SQL Microsoft Official Curriculum (MOC 20761)

Querying Data with Transact SQL Microsoft Official Curriculum (MOC 20761) Querying Data with Transact SQL Microsoft Official Curriculum (MOC 20761) Course Length: 3 days Course Delivery: Traditional Classroom Online Live MOC on Demand Course Overview The main purpose of this

More information

SQL. SQL Queries. CISC437/637, Lecture #8 Ben Cartere9e. Basic form of a SQL query: 3/17/10

SQL. SQL Queries. CISC437/637, Lecture #8 Ben Cartere9e. Basic form of a SQL query: 3/17/10 SQL CISC437/637, Lecture #8 Ben Cartere9e Copyright Ben Cartere9e 1 SQL Queries Basic form of a SQL query: SELECT [DISTINCT] target FROM relations WHERE qualification target is a list of a9ributes/fields

More information

Relational Query Optimization

Relational Query Optimization Relational Query Optimization Module 4, Lectures 3 and 4 Database Management Systems, R. Ramakrishnan 1 Overview of Query Optimization Plan: Tree of R.A. ops, with choice of alg for each op. Each operator

More information

Learn Relational Database from Scratch. Dan Li, Ph.D. Associate Professor Computer Science Eastern Washington University

Learn Relational Database from Scratch. Dan Li, Ph.D. Associate Professor Computer Science Eastern Washington University Learn Relational Database from Scratch Dan Li, Ph.D. Associate Professor Computer Science Eastern Washington University Self-Introduction Associate professor of Computer Science at EWU Area of expertise

More information

Lecture 8. Database Management and Queries

Lecture 8. Database Management and Queries Lecture 8 Database Management and Queries Lecture 8: Outline I. Database Components II. Database Structures A. Conceptual, Logical, and Physical Components III. Non-Relational Databases A. Flat File B.

More information

The SELECT-FROM-WHERE Structure

The SELECT-FROM-WHERE Structure SQL Queries 1 / 28 The SELECT-FROM-WHERE Structure SELECT FROM WHERE From relational algebra: SELECT corresponds to projection FROM specifies

More information

Advanced SQL Processing Prepared by Destiny Corporation

Advanced SQL Processing Prepared by Destiny Corporation Advanced SQL Processing Prepared by Destiny Corporation Summary Functions With a single argument, but with other selected columns, the function gives a result for all the rows, then merges the back with

More information

Introduction to Geographic Information Science. Updates. Last Lecture. Geography 4103 / Database Management

Introduction to Geographic Information Science. Updates. Last Lecture. Geography 4103 / Database Management Geography 4103 / 5103 Introduction to Geographic Information Science Database Management Updates Last Lecture We tried to explore the term spatial model by looking at definitions, taxonomies and examples

More information

Final Exam Review 2. Kathleen Durant CS 3200 Northeastern University Lecture 23

Final Exam Review 2. Kathleen Durant CS 3200 Northeastern University Lecture 23 Final Exam Review 2 Kathleen Durant CS 3200 Northeastern University Lecture 23 QUERY EVALUATION PLAN Representation of a SQL Command SELECT {DISTINCT} FROM {WHERE

More information

Lecture 7: Functions. CS1068+ Introductory Programming in Python. Dr Kieran T. Herley 2018/19. Department of Computer Science University College Cork

Lecture 7: Functions. CS1068+ Introductory Programming in Python. Dr Kieran T. Herley 2018/19. Department of Computer Science University College Cork Lecture 7: Functions CS1068+ Introductory Programming in Python Dr Kieran T. Herley 2018/19 Department of Computer Science University College Cork Summary Functions in Python. Terminology and execution.

More information

The SELECT-FROM-WHERE Structure

The SELECT-FROM-WHERE Structure SQL Queries 1 / 28 The SELECT-FROM-WHERE Structure SELECT FROM WHERE From relational algebra: SELECT corresponds to projection FROM specifies

More information

Concepts of Database Management Eighth Edition. Chapter 2 The Relational Model 1: Introduction, QBE, and Relational Algebra

Concepts of Database Management Eighth Edition. Chapter 2 The Relational Model 1: Introduction, QBE, and Relational Algebra Concepts of Database Management Eighth Edition Chapter 2 The Relational Model 1: Introduction, QBE, and Relational Algebra Relational Databases A relational database is a collection of tables Each entity

More information

Learn Well Technocraft

Learn Well Technocraft Note: We are authorized partner and conduct global certifications for Oracle and Microsoft. The syllabus is designed based on global certification standards. This syllabus prepares you for Oracle global

More information

Querying Data with Transact-SQL (20761)

Querying Data with Transact-SQL (20761) Querying Data with Transact-SQL (20761) Formato do curso: Presencial e Live Training Preço: 1630 Nível: Iniciado Duração: 35 horas The main purpose of this 5 day instructor led course is to give students

More information

Introduction to Database. Dr Simon Jones Thanks to Mariam Mohaideen

Introduction to Database. Dr Simon Jones Thanks to Mariam Mohaideen Introduction to Database Dr Simon Jones simon.jones@nyumc.org Thanks to Mariam Mohaideen Today database theory Key learning outcome - is to understand data normalization Thursday, 19 November Introduction

More information

Applied Databases. Sebastian Maneth. Lecture 5 ER Model, normal forms. University of Edinburgh - January 25 th, 2016

Applied Databases. Sebastian Maneth. Lecture 5 ER Model, normal forms. University of Edinburgh - January 25 th, 2016 Applied Databases Lecture 5 ER Model, normal forms Sebastian Maneth University of Edinburgh - January 25 th, 2016 Outline 2 1. Entity Relationship Model 2. Normal Forms Keys and Superkeys 3 Superkey =

More information

SQL QUERIES. CS121: Relational Databases Fall 2017 Lecture 5

SQL QUERIES. CS121: Relational Databases Fall 2017 Lecture 5 SQL QUERIES CS121: Relational Databases Fall 2017 Lecture 5 SQL Queries 2 SQL queries use the SELECT statement General form is: SELECT A 1, A 2,... FROM r 1, r 2,... WHERE P; r i are the relations (tables)

More information

Lecture 8: Context Free Grammars

Lecture 8: Context Free Grammars Lecture 8: Context Free s Dr Kieran T. Herley Department of Computer Science University College Cork 2017-2018 KH (12/10/17) Lecture 8: Context Free s 2017-2018 1 / 1 Specifying Non-Regular Languages Recall

More information

Database Technology Introduction. Heiko Paulheim

Database Technology Introduction. Heiko Paulheim Database Technology Introduction Outline The Need for Databases Data Models Relational Databases Database Design Storage Manager Query Processing Transaction Manager Introduction to the Relational Model

More information

4. SQL - the Relational Database Language Standard 4.3 Data Manipulation Language (DML)

4. SQL - the Relational Database Language Standard 4.3 Data Manipulation Language (DML) Since in the result relation each group is represented by exactly one tuple, in the select clause only aggregate functions can appear, or attributes that are used for grouping, i.e., that are also used

More information

Essay Question: Explain 4 different means by which constrains are represented in the Conceptual Data Model (CDM).

Essay Question: Explain 4 different means by which constrains are represented in the Conceptual Data Model (CDM). Question 1 Essay Question: Explain 4 different means by which constrains are represented in the Conceptual Data Model (CDM). By specifying participation conditions By specifying the degree of relationship

More information

TECHNOLOGY COMPETENCY ASSESSMENT MODULE Microsoft Access

TECHNOLOGY COMPETENCY ASSESSMENT MODULE Microsoft Access TECHNOLOGY COMPETENCY ASSESSMENT MODULE Microsoft Access This module was developed to assist students in passing the SkillCheck Incorporated Access 2003 Technology Competency Assessment. It was last updated

More information

Lecture 11: while loops CS1068+ Introductory Programming in Python. for loop revisited. while loop. Summary. Dr Kieran T. Herley

Lecture 11: while loops CS1068+ Introductory Programming in Python. for loop revisited. while loop. Summary. Dr Kieran T. Herley Lecture 11: while loops CS1068+ Introductory Programming in Python Dr Kieran T. Herley Python s while loop. Summary Department of Computer Science University College Cork 2017-2018 KH (24/10/17) Lecture

More information

Lecture 06. Fall 2018 Borough of Manhattan Community College

Lecture 06. Fall 2018 Borough of Manhattan Community College Lecture 06 Fall 2018 Borough of Manhattan Community College 1 Introduction to SQL Over the last few years, Structured Query Language (SQL) has become the standard relational database language. More than

More information

Databases. Jörg Endrullis. VU University Amsterdam

Databases. Jörg Endrullis. VU University Amsterdam Databases Jörg Endrullis VU University Amsterdam The Relational Model Overview 1. Relational Model Concepts: Schema, State 2. Null Values 3. Constraints: General Remarks 4. Key Constraints 5. Foreign Key

More information

8) A top-to-bottom relationship among the items in a database is established by a

8) A top-to-bottom relationship among the items in a database is established by a MULTIPLE CHOICE QUESTIONS IN DBMS (unit-1 to unit-4) 1) ER model is used in phase a) conceptual database b) schema refinement c) physical refinement d) applications and security 2) The ER model is relevant

More information

SQL: The Sequel. Phil Rhodes TAIR 2013 February 11, Concurrent Session A6

SQL: The Sequel. Phil Rhodes TAIR 2013 February 11, Concurrent Session A6 SQL: The Sequel Phil Rhodes TAIR 2013 February 11, 2013 Concurrent Session A6 Topics Brief review Subqueries Updating Data Conditional Logic Multi table joins Reporting Topics Brief review Subqueries Updating

More information

INTRODUCTION TO PROC SQL JEFF SIMPSON SYSTEMS ENGINEER

INTRODUCTION TO PROC SQL JEFF SIMPSON SYSTEMS ENGINEER INTRODUCTION TO PROC SQL JEFF SIMPSON SYSTEMS ENGINEER THE SQL PROCEDURE The SQL procedure: enables the use of SQL in SAS is part of Base SAS software follows American National Standards Institute (ANSI)

More information

RDBMS- Day 4. Grouped results Relational algebra Joins Sub queries. In today s session we will discuss about the concept of sub queries.

RDBMS- Day 4. Grouped results Relational algebra Joins Sub queries. In today s session we will discuss about the concept of sub queries. RDBMS- Day 4 Grouped results Relational algebra Joins Sub queries In today s session we will discuss about the concept of sub queries. Grouped results SQL - Using GROUP BY Related rows can be grouped together

More information

MariaDB Crash Course. A Addison-Wesley. Ben Forta. Upper Saddle River, NJ Boston. Indianapolis. Singapore Mexico City. Cape Town Sydney.

MariaDB Crash Course. A Addison-Wesley. Ben Forta. Upper Saddle River, NJ Boston. Indianapolis. Singapore Mexico City. Cape Town Sydney. MariaDB Crash Course Ben Forta A Addison-Wesley Upper Saddle River, NJ Boston Indianapolis San Francisco New York Toronto Montreal London Munich Paris Madrid Cape Town Sydney Tokyo Singapore Mexico City

More information

Relational Algebra Part I. CS 377: Database Systems

Relational Algebra Part I. CS 377: Database Systems Relational Algebra Part I CS 377: Database Systems Recap of Last Week ER Model: Design good conceptual models to store information Relational Model: Table representation with structures and constraints

More information

FIT 100 More Microsoft Access and Relational Databases Creating Views with SQL

FIT 100 More Microsoft Access and Relational Databases Creating Views with SQL FIT 100 More Microsoft Access and Relational Databases Creating Views with SQL Creating Views with SQL... 1 1. Query Construction in SQL View:... 2 2. Use the QBE:... 5 3. Practice (use the QBE):... 6

More information

After completing this course, participants will be able to:

After completing this course, participants will be able to: Querying SQL Server T h i s f i v e - d a y i n s t r u c t o r - l e d c o u r s e p r o v i d e s p a r t i c i p a n t s w i t h t h e t e c h n i c a l s k i l l s r e q u i r e d t o w r i t e b a

More information

Access Basics: When and How

Access Basics: When and How Access Basics: When and How Hal Jankowski CACUBO Winter Workshop Kansas City, MO April 2014 Learning outcome disclaimer Access is a complex tool that requires significant hands on time to become familiar.

More information

20461: Querying Microsoft SQL Server 2014 Databases

20461: Querying Microsoft SQL Server 2014 Databases Course Outline 20461: Querying Microsoft SQL Server 2014 Databases Module 1: Introduction to Microsoft SQL Server 2014 This module introduces the SQL Server platform and major tools. It discusses editions,

More information

IBM Software Group Information Management Software. The Informix Detective Game (Student Handout)

IBM Software Group Information Management Software. The Informix Detective Game (Student Handout) The Informix Detective Game (Student Handout) Before you start playing the game 1. Start Informix a) Start Informix command prompt Start all Programs IBM Informix 11.70 ol_informix_1170 b) Start DBAccess

More information

Other Relational Query Languages

Other Relational Query Languages APPENDIXC Other Relational Query Languages In Chapter 6 we presented the relational algebra, which forms the basis of the widely used SQL query language. SQL was covered in great detail in Chapters 3 and

More information

Database Programming with PL/SQL

Database Programming with PL/SQL Database Programming with PL/SQL Review of SQL Joins 1 Copyright 2013, Oracle and/or its affiliates. All rights Objectives In this lesson, you will review how to construct and execute SELECT statements:

More information